I am templating a resource page that has 5 different types of resources. I want to display a specific icon based on the type of resource. I want to do this programmatically so that later, users can upload a document, choose what type of resource it is, and the icon will automatically be displayed.
Now I'd like to be able to complete the logic of this inside the node--resource-asset.html.twig template using a for or if statement.
This is the kint display for the field_resource_type array. I want to generate the icon based on the markup string. This is what I've tried
{% for markup in content.field_resource_type %}
{% if markup == 'Datasheet' %}
<img class="icon" src="/img/icon_datasheet.png">
{% elseif markup == 'Whitesheet' %}
<img class="icon" src="/img/icon_whitepaper.png">
{% else %}
<img class="icon" src="/img/icon_casestudy.png">
{% endif %}
{% endfor %}
Nothing renders. Any suggestions on what I should be using as the key to call the correct part of the field?
markup
will never get value 'Datasheet', Try{% for markup in content.field_resource_type[0] %}
. This for statement is really necessary? Why you just try get content.field_resource_type[0]['#markup'] ?