Sulu CMS: Is there a way to see in the template, weather it is a render preview? - sulu

I would like to display a content warning in the render preview, if something is not configured correctly. It should only be visible to logged in content managers thou.
Is there a way to know in the template, if it is a logged in user or a render preview?
as a basic idea:
{% if menu.root_uuid %}
<!-- do amazing things -->
{% elseif is_render_preview() %}
<div class="warning">
The menu can not be displayed, because no root folder is selected.
</div>
{% endif %}

The controller is given a $preview attribute to know if its a preview or not. In twig there is no variable but you can access controller attributes the following way:
{% if app.request.attributes.get('preview') %}
{# do something only for preview #}
{% endif %}

Related

Shopify pop-up - adding checkout button

I am trying to add a "checkout" button to the standard cart popup that occurs when a customer "adds to cart".
I am using the Shopify debut theme, but the question would apply to pretty much any Shopify theme that has a "add to cart pop-up".
It was pretty easy to add the extra code to "cart-popup.liquid", as I copied it over from "cart-template.liquid".
The button itself is showing, but it doesn't work.
The other buttons I added, checkout with Paypal and Amazon checkout all show and also work fine.
Below is the 'donor code'
<div class="cart__buttons-container">
<div class="cart__submit-controls">
<input type="submit" name="checkout" class="cart__submit btn btn--small-wide" value="{{ 'cart.general.checkout' | t }}">
</div>
<div class="cart__error-message-wrapper hide" role="alert" data-cart-error-message-wrapper>
<span class="visually-hidden">{{ 'general.accessibility.error' | t }} </span> {% include 'icon-error' %}
<span class="cart__error-message" data-cart-error-message></span>
</div>
{%- if additional_checkout_buttons -%}
<div class="additional-checkout-buttons">{{ content_for_additional_checkout_buttons }}</div>
{%- endif -%}
</div>
And this extra code shows the buttons correctly on the popup.
the buttons all work except for the main one! checkout
I think something is missing ... any suggestions?
Thanks!

How can i add class inside content on TWIG - Drupal

I have this div
<div class="col-md-6 column_must">
<p class="must_title"> {{ content.field_code_must_title }}</p>
<p class="must_desc"> {{ content.field_code_must_desc }}</p>
</div>
I want to insert this 2 class in content, but the result shows the then the content, but i want the content inside in that
Can you help me?
Thanks
You will need to add a twig file to edit the fields field_code_must_title and field_code_must_desc, there you'll be able to add your classes to the fields.
What I would suggest you is on the custom theme folder that you will have on your drupal installation, create the twig files for these two fields and then copy inside the field.html.twig from the drupal core theme and make the changes in place.
Follow this link for more insights:
https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-for-custom-module

AEM Sightly - How to loop through component child nodes

I have a 'container' component for housing child components. Essentially, a container for holding tabs of content, where the user can drag in as many 'tabs' as they choose.
The code is as such:
<!--/* Tab Container Component */-->
<div data-sly-test="${wcmmode.edit}"><h2>Drag a 'Tab Panel' below:</h2></div>
<ul data-sly-list.tab="${list of children in the tab-container parsys}">
<li>${tab.tabName}</li> //these will be the tabs using jQuery-UI
</ul>
<div data-sly-resource="${ #path='tab-container',resourceType='wcm/foundation/components/parsys'}" data-sly-unwrap></div>
And the 'tab' component:
<!--/* Tab Panel Component */-->
<div class="tab-panel">
<div data-sly-resource="${ #path='tab- panel',resourceType='wcm/foundation/components/parsys'}" data-sly-unwrap></div>
</div>
What I want to achieve is to use the container component to loop through the items in its parsys and pull out the property 'tabName' of each item. The node structure ends up as shown:
This might work in your case:
<ul data-sly-list.tab="${resource.listChildren}">
<li>${tab.name}</li> //these will be the tabs using jQuery-UI
</ul>
Basically, the tab-container is your parsys and resource.listChildren will list all the child resources/nodes. tab.name is provided by HTL which will give you tab_panel, tab_panel_1134.., etc.. Other properties inside of each tab-panel (tab) too can be accessed.
Another way to get directly to a resource is with data-sly-use:
with this you can reach any resource in AEM. Docs here (look for data-sly-use with resources).
Good Luck...

Laravel checkbox inside form won't check

I'm stuck in Laravel 5.2 trying to be able to interact with a checkbox inside a form.
When I click them, they just light up, but won't get checked.
It seems that when I remove the form tags (or blade tags), the checkboxes can be checked, but I need them to be inside a form to submit if checked or not...
code is located in home.blade.php in the #section('content')
This seems to work:
#foreach($items as $item)
<li>
<input id="item" name="id" onClick="this.form.submit" type="checkbox" value="{{ $item->id }}" {{ $item->done ? 'checked' : ''}} />
{{ $item->name }}
</li>
#endforeach
Image of working checkboxes
But it fails here:
#foreach($items as $item)
<li>
{{Form::open()}}
<input id="item" name="id" onClick="this.form.submit" type="checkbox" value="{{ $item->id }}" {{ $item->done ? 'checked' : ''}} />
{{ $item->name }}
{{Form::close()}}
</li>
#endforeach
Image checkboxes not working
Thanks for helping!
Move your Form open & Form close tag outside of foreach. It is creating many form as much as the foreach looped. Your code should look like this:
{{Form::open()}}
#foreach($items as $item)
<ul>
<li>
<input id="item" name="id" onClick="this.form.submit" type="checkbox" value="{{ $item->id }}" {{ $item->done ? 'checked' : ''}} />
<label for="id">{{ $item->name }}</label>
</li>
</ul>
#endforeach
{{Form::close()}}
It looks like you are submitting the form as an onclick event of the checkbox. You are essentially submitting the form as soon as the checkbox is clicked, and since the form submits to itself, it is reloading in its default state (unchecked). By the time you have finished clicking it, the page has reloaded and it is unclicked again.
The reason why you don't see this when you remove the form tag, is because the event (submitting the form) no longer does anything, because there is no longer a form to submit.
I am referring to this offending attribute:
onClick="this.form.submit"

Highlight current menu item lift

How can I determine the page I am currently on in Lift?
In django, for example, in my base template I had simple checks like these:
<li {% ifequal main_navigation "home" %} class="selected"{%endifequal%}>
Home
</li>
<li {% ifequal main_navigation "risk"%}class="selected"{%endifequal%}>
Risk
</li>
<li {% ifequal main_navigation "contact" %}class="selected"{%endifequal%}>
Contact
</li>
here, the if determines what the context variable main_navigation is set to.
I'm assuming you're using the sitemap for your menu.
When rendering the menu with the Menu.builder snippet you can use additional parameters to further tweak the menu. This example will render only the first level of the menu and adds class current to the menu item if it's the current page.
designer friendly example:
<div class="lift:Menu.builder?level=0;expand=false;li_item:class=current"></div>
or
<lift:Menu.builder li_item:class="selected" level="0" expand="false" />
for more details see the lift wiki: http://www.assembla.com/wiki/show/liftweb/SiteMap
If you use Lift's SiteMap and Menu functionality, I think this is taken care of automatically. You can read about it here: http://simply.liftweb.net/index-3.2.html#toc-Subsection-3.2
To answer your broader question, within a Snippet (not a template), you can use LiftRules.context, which returns an HTTPContext including a path attribute.