1

I need to add a separator if there are a multiple of types. How can this be done in a for loop?

{% for type in entry.buildType %}{{ type }}{% endfor %}

The outcome is similar to a breadcrumb nav, with an added "/", however the separator should only be placed in between - not for the last.

1
  • Twig also has a very useful join filter, which does exactly this.
    – Jamie Wade
    Jul 23, 2018 at 10:29

1 Answer 1

3
{% for type in entry.buildType %}
{{ type }}
{% if not loop.last %}/{% endif %}
{% endfor %}

See: https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.