Score:0

print description and field value directly in taxonomy-term--drzava.html.twig

cn flag

First I disable view for taxonomy-term, so I can use taxonomy-term--drzava.html.twig, where drzava is name of vocabulary.

How to print description and filed value for taxonomy-term directly, without using

field--taxonomy-term--description--drzava.html.twig

{{ content.description }} or {{ content.field_flag_code}}

I have problem to analyze devel output. I try {{ content.description.value }} but its do not work.

and for field, I try something like this but its do not work. {{ content.field_flag_code.0.value }}

In Devel there is Definition, Render and Load, what from this tri tabs I need to look for twig?

Thanks for the help in advance.

enter image description here

Score:1
cn flag

The description field is a formatted text field which should be printed as processed text render element:

taxonomy-term.html.twig:

{{ {
  '#type': 'processed_text',
  '#text': term.description.value,
  '#format': term.description.format,
} }}

If you want to get rid of the <p> tag you have to configure the field with a a different text format or use |render|striptags on a variable stored like in the linked topic.

The other field value:

{{ term.field_flag_code.0.value }}
cn flag
Thank you a lot. I learn one very nice staf. https://prnt.sc/26ja49b I edit a litle your answer
4uk4 avatar
cn flag
About your edit, the other field doesn't seem to be a formatted text field.
cn flag
I was plane to use field_flag_code field as css marker. <span class="flag-50 flag-icon flag-icon-en flag-icon-squared "> like flag-icon-{{ term.field_flag_code.0.value }} . I was use the some method and its work. :)
Score:1
cn flag

I remembered. I hadn't used drupal for a while, so I forgot.

I use Devel:

{{ kint(content.description['#items'].getValue()|first.value) }}

and in taxonomy-term--drzava.html.twig, I Use

{{ content.description['#items'].value }}

enter image description here

This is my output. But I don't understand why its display <P></P>

cn flag
`<p>` tags are probably being added because the description is passed through an input filter, which adds the tags automatically. If you want to get rid of them, use `striptags`: https://twig.symfony.com/doc/2.x/filters/striptags.html
4uk4 avatar
cn flag
Yes, this is clear in the debug output because the field has a property `format`. The correct way is then to output it as processed_text to apply the output filters of the text format, too. See https://drupal.stackexchange.com/questions/238762/how-to-safely-render-node-body-on-a-custom-variable. This link is for a node, in a taxonomy term template use `term`.
cn flag
@4k4 This is very nice solution. Where to put '#test' => $term in some preprocess functions or..? I always afraid to write preprocess functions.
4uk4 avatar
cn flag
You don't need a preprocess hook because the variable `term` is already available, see the documentation at the top of template. I post a code example as answer.
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.