This is my first question on the forum. I am currently developing a site (Drupal 8.8.1). I am developing it in a sub directory on the server and not using Drush, the server belongs to a large academic institution and they do not give me access to set up a localhost. I have a good understanding of HTML and CSS, but only the very basics of PHP.

I have a very specific theming issue I need some help with. I have a taxonomy vocabulary (a list of authors) which is displayed using entity reference (label format - link to ref entity) as a field which appears on certain nodes and views. This renders the author's name as a link that links to all other instances of that same author. This is fine, but I need to make some of the terms of this vocabulary not appear or function as a link.

The rendered HTML for the specific field I am interested in looks like this:

<div class="field--item"><a href="/__D8/taxonomy/term/9" hreflang="en">AUTHOR'S NAME</a></div>

What I need is to do is to be able to remove the href from the anchor tag on specific taxonomy terms and add something like class="{{ name }}", or somehow get the taxonomy term ID to determine its CSS class attribute. I have tried to do this by overriding the taxonomy-term.html.twig and the field.html.twig (renaming it to specifically target my field: field--node--field-researchers--publications.html.twig). I put these two files in my MYTHEME/templates directory and disabled Views Taxonomy Term view, but I cannot make the class tag appear.

I'm not even sure if this is the best way to get the effect I want, but I can't think of another way at the moment. Any help would be greatly appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.