Home » PHP » Twig » Top Twig Template Interview And Answer Part 5

Top Twig Template Interview And Answer Part 5

1.How can we loop the array in twig template?

{% for item in test %}
      
{% endfor %}

2. How can the array element start with 0 or 1 index value in twig template?

{% for item in test %}
      {{ loop.index0 }}   {# Index will start from 0 #}
      {{ loop.index }}    {# Index will start from 1 #}
{% endfor %}

3. How can i check that data is available or not in twig template?

{% if data.title is not empty %}
{% endif %}

4. What is the renderlet in twig template?

The renderlet is a special container which is able to handle every element in Pimcore (Documents, Assets, Objects). You can decide in your controller/action what to do with the element which is linked to the renderlet.

{{ pimcore_renderlet('myRenderlet', {
controller: 'content',
action: 'gallery-renderlet'
}) }}

5. How can we use spaceless in twig template?

{%-  -%}

6. How can we get request parameter value in twig template?

{{ app.request.locale }}

7. How can we retrieve the value of a property named “hideNavigation” in twig template?

{% set hideNavigation = document.getProperty(‘hideNavigation’) %}

Check Also

Top Twig Template Interview And Answer Part 2

1. How can we get parameter value from property and match with local array value …

Leave a Reply

Your email address will not be published. Required fields are marked *