Christien
Christien

Reputation: 120

Twig template with variable

My twig template has for loop, and I am trying to add a varable to it. How do I do this?

The ('var') needs to be the variable > content. + var + .related.buttons

{% include '@PleinCatalog/Theme/includes/themeCatergory.html.twig' with {'var':'something'} %}
{% for button in content.('var').related.buttons %}
      <a href="{{ button.url }}" class="btn btn-block btn-success">{{ button.title }}</a>
{% endfor %}

Upvotes: 0

Views: 119

Answers (1)

Stefan Kunze
Stefan Kunze

Reputation: 618

I have a similar for loop in my projects, where I include templates with some options.

Based on your example - it can be uses like that:

{% for button in content[var].related.buttons %}
    …
{% endfor %}

Upvotes: 2

Related Questions