Showing posts with label foreach loop in twig file. Show all posts
Showing posts with label foreach loop in twig file. Show all posts

Thursday 5 July 2018

Loop in twig file drupal 8.

Here we have syntax of for/foreach loop in Twig file. Please have a look the syntax..
Suppose we have array with name of 'data', so our for loop for twig will be.

{% for key, value in data %}
      {{ key }} | {{ value }}
{% endfor %}

                      OR

In case we need key with value then our syntax will be..

<ul>
 {% for key, value in data %}
   {% if key!= ' '%}

      <li class="{{ key }}"> {{ value }}</li>
    {% endif %}
{% endfor %}
</ul>

                       OR

In case we just need value without key then our syntax will be..

{% for value in data %}
   {{ value }}     
{% endfor %}

Note: If have any suggestions or issue regarding 'Loop in twig file drupal 8' then you can ask by comments.

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...