Score:1

How to display the parent taxonomy term of the "Tags" field?

mw flag

On my Drupal 9 site, I created taxonomy terms in the "tags" vocabulary (the vocabulary and the default field of the "article" content type) :

enter image description here

When I create a node, I select a taxonomy term in the form (for example "ICO"). The node displays the "tags" field :

enter image description here

I want that if the node has the term "ICO", it also displays the parent terms. Like this :

Catégories : Culture geek, crypto, ICO

How can I do this? I did not find anything in the view mode regarding this field.

Stefanos Petrakis avatar
in flag
Did you come across this contrib? https://www.drupal.org/project/hierarchical_term_formatter
mathieu avatar
mw flag
@StefanosPetrakis It works thank you
Stefanos Petrakis avatar
in flag
Lovely, it would be great to post what worked for you here as an answer, to assist others that land here with the same question.
mathieu avatar
mw flag
@StefanosPetrakis I cannot answer my own question. You must make an answer and I validate it
Stefanos Petrakis avatar
in flag
sorry, thought you could. I will post one in the next couple of minutes.
Score:2
in flag

You need a field formatter for that, luckily there is one already that covers this use case, it's the Hierarchical Term Formatter that works with Drupal 9.

  1. For the given taxonomy structure:

enter image description here

  1. By selecting the terminal term (in this example 'jodri')

enter image description here

  1. Installing the Hierarchical Term Formatter, with its default configuration

enter image description here

  1. Results in the following display of the rendered node.

enter image description here

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.