How can I display node taxonomy terms field in node templates of Drupal 8?
We do this in Drupal 7 by add this code to node.tpl.php file:
print render($content['field_tags']);
I tried adding the below code in Drupal 8:
{{ content.field_tags }}
but with this code have problems:
If I add some styles or make some changes to
field--node--field-tags.html.twig
file these changes displays in all content types also.If I don't want to show default taxonomy terms in the bottom of article nodes (I want to move and show taxonomy terms in the top of the article) and I assign "Hidden" value in "Administration>Structure>Content types>Article" in "Format" section, this settings cause to not displays all the taxonomy terms fields in throughout of the article nodes at all.
Taxonomy terms Label always display even if no tags added to the node. How can I show taxonomy terms label and their values only when have been added any tags to it?
if
onnode.html.twig
something like{% if content.field_tags %} <div class="article_tags"> <h3>{{ "Tags"|t }}</h3> {{ content.field_tags }} </div> {% endif %}
and onfield--node--field-tags.html.twig
just something like{% for item in items %} {{ item.content }} {% endfor %}
. Its better you use the proper template file for each element, try not use a node template to format a field, will be easier to maintain in the future.