0

How I do with twig this:

I got list -field where I got differents color:

black|Black

grey|Grey


black = background-color: #000;

grey = background-color: #eee;


When I select Black it will appear somewhere on the node or field.

<div class="black">Example</div>
1

One way to do this is provide a field template for that field that just prints the value and no markup:

field--your-field-name.html.twig:

{% for item in items %}
  {{ item.content }}
{% endfor %}

Then in the main template, wherever you want to output that field value, you would have:

<div class="{{ content.your_field_name|trim }}">Example</div>

The result should be just the field value, with no whitespace, so "black" or "grey".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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