Last active
February 27, 2018 00:31
-
-
Save acabouet/d9a17849f7c5dbfedb88d7592c3017e7 to your computer and use it in GitHub Desktop.
Drupal 8 - Get values as taxonomy term names from a taxonomy term reference field and print them out in a Twig template as classes. Especially handy for using with Isotope filters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Create classes array. The 'node' class is required for contextual edit links. #} | |
{% set categories = [] %} | |
{% set classes = ['integration', 'node'] %} | |
{% for key, item in content.field_integration_cat if key|first != '#' %} | |
{% set categories = categories | merge([ item['#title'] | replace({' ':''}) ]) %} | |
{% endfor %} | |
{% for item in categories %} | |
{% set classes = classes | merge([item]) %} | |
{% endfor %} | |
<section {{ attributes.addClass(classes) }}> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment