1

For example Taxonomy Terms field Label is always displayed even if no tags added to it. How can I show Taxonomy Terms field's Label and its values (tag's links), only when there have been a value added to it?

I try to achieve that by adding conditionals based fields, something like below code to node template:

{% if content.field_tag is not empty %}
{{ content.field_tag }}
{% endif %}

or

{% if content.field_tag %}
{{ content.field_tag }}
{% endif %}

According to the article:Comparison of PHP Template and Twig theming paradigms but whatever I try I can't get any result.

6
  • 2
    Are you sure it behaves as the way u explained ?? because i installed fresh drupal and created a content article with no tag the label Tag dint show up Commented Sep 19, 2016 at 5:49
  • Thanks for reply, but my mean when you add Taxonomy Terms field to the content, in this case Taxonomy Terms field Label always be displayed. Commented Sep 19, 2016 at 8:41
  • You may have to use form_alter . Commented Sep 19, 2016 at 9:11
  • Just for confirmation before posting an answer you are talking abt node-edit page ie node/nid/edit page correct? Commented Sep 19, 2016 at 12:26
  • Thanks for reply, but my means not that page. Commented Sep 19, 2016 at 13:00

1 Answer 1

1

almost you did , instead of content.FIELD_MACHINENAME use node.FIELD_MACHINENAME.value I mean try something like

{% if node.field_tag.value %}
{{ content.field_tag }}
{% endif %}

for make sure that this solution work correctly(for debug) try {{ kint(node.field_tag }}.

1
  • @MojtabaReyhani you're welcome, we are here to help each other.
    – Yuseferi
    Commented Sep 25, 2016 at 5:49

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.