I'm trying to use two taxonomy items to build a button on my template. The logic is:
If this node is exactly equal to taxonomyTermFromVocabularyA
Print a button on the page with a URL built out of taxonomyTermFromVocabularyB
I thought I was doing well when a simple test proved that my terms were available. In the template, I tested by adding:
<h3>{{ content.field_taxonomy_resource_type }}</h3>
<h3>{{ content.field_taxonomy_topic }}</h3>
And out came the expected values on the page:
Topic Page
Oral Health
However, once I tried to actually use the terms I captured it never worked. The first part of the logic, where the button will eventually be built, I wrote as:
{% if content.field_taxonomy_resource_type == "Topic Page" %}
<p> hello, it's working! </p>
{% endif %}
produces no content at all. I expected to see my test paragraph sentence "hello, it's working!" appear on the page.
My best google-foo hasn't helped me at all and, alas, my soul is being crushed. I fear it's something completely obvious that I am just ignorant about.
Can anyone point me to the error of my ways? Why doesn't my twig if
statement work?
@clive was absolutely right in the suggestion below that I was naming the array and not the particular item I needed when constructing my if
statement. His correction to my code:
{% if node.field_taxonomy_resource_type.entity.label == "Topic Page" %}
is not working though, and the best I can tell is that the variable is unavailable to me. When I dump the variable using {{ dump(node.field_taxonomy_resource_type.entity) }}
, I just get NULL.
Clive's answer worked as soon as I changed out node to paragraph. Thanks!
{% if paragraph.field_taxonomy_resource_type.entity.label == "Topic Page" %}