-1

I added a taxonomy field inside a view.

taxonomy field

I need to show the term name on the page in a grouped way, like this.

  • taxonomy term1 name

    • title1

    • content1

    • title2

    • content2

  • taxonomy term2 name

    • title1

    • content1

    • title2

    • content2

I am not sure what to put on template file to show the term name. I tried {{term_node_tid}}, but it doesn't show any output. On the view preview, the output is exactly what I expect.

views preview image

How do I show it that way?

0

If you only have one term in each node then you can use the "All taxonomy terms" Field. There is a token for the term Name you can use in the Rewrite results section of the Field Settings:

Rewrite results
Override the output of this field with custom text
{{ term_node_tid__name }}

Replacement patterns

When you open Rewrite results and enable the Override option you will see the Replacement patterns below the text area. Open it and you will see the token list. Copy your token and paste it in the textarea above it.

If you have more than one term on any node the All taxonomy terms Field will group the combinations and treat them as independent output, which is probably not what you want.

In that case you need to use a more direct approach, the actual Taxonomy term Reference Field from your Content Type. This field gives you the option to show the values in different Views results rows (if it's a multivalue field).

When you disable showing all the values in the same row, and Group by that field, you will get independent terms as group headings and all their content listed below them.

| improve this answer | |
  • right now, individual terms showing for all the contents, but not sure what to put on twig file to show the content grouped by terms. – Pranab Nov 22 at 20:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.