how to add attributes of the parent taxonomy in the DOM? I am displaying a taxonomy &quot;category&quot; on a node, a view of that node ,and a search facet.
This taxonomy has 2 levels.
How can i add to the rendered HTMLs, i guess using preprocessing hooks, an attribute indicating the taxonomy parent id ?
I would need to apply CSS differently to the taxonomy buttons depending on the parent.
You can add the relevant Taxonomy parent Field to your Views, make it display the term ID. This way you get that information available as a token.
You can hide that field with Exclude from display and position it above all the other fields, so you can use it as a token in all of them without worrying about the position.
Then edit the Style settings of your &quot;Parent&quot; field that you want to style and enable the Create a CSS class option. You can enter the token for your parent TID in there.
Since css classes can't start with numbers make sure to enter a safe start for the class, for example: myclass-{{ tid }}
To find the list of tokens you'll have to temporarily enable the option Rewrite results &gt; Override the output of this field with custom text &gt; Replacement patterns.
You may need to Customize field and label wrapper HTML and/or Use field template depending on your particular configuration and output to get the class to show up.

Alternatively, you can construct the output of your field on your own with the Override the output of this field with custom text and enter what you want the HTML to show:
&lt;div class=&quot;myclass-{{ tid }}&quot;&gt;{{ field_output }}&lt;/div&gt;