Score:0

Why does twig tweak's drupal_field() function convert special characters to HTML entities?

cn flag

I'm using the following inside views to change the page title to the term name but it renders term names with & in them as &

In the views override title section I'm using.

{{ drupal_field('name', 'taxonomy_term', arguments.tid) }}

I have tried adding render|striptags at the end of the function but that doesn't seem to work.

id flag
I am sure it is Twig doing so, not Twig Tweak. You can test that with the unsafe `|raw` filter.
Score:0
us flag

An option is to try removing the auto escaping of the output with twig's autoescape tag

In this case, the code would look something like

{% autoescape false %}
  {{ drupal_field('name', 'taxonomy_term', arguments.tid) }}
{% endautoescape %}

Also, as already suggested in the comments, the raw filter could be used. Note however it is not considered safe, so in case of usage, one should be certain the data is not harmful. Combination of both could be helpful as well.

4uk4 avatar
cn flag
`{% autoescape false %}` and `|raw` have the same effect and are equally unsafe. The difference is that the filter applies to a single variable and the autoescape tag to all variables in the tagged code block.
cn flag
I've tried both of those but it hasn't worked. I'm adding this in the views form so maybe that is affecting the output.
Ivaylo Tsandev avatar
us flag
Good point, thanks. I am wondering though - if it is a view page, why not use `function my_module_views_post_render($view)` and set the title programmatically inside with `$view->setTitle('NEW TITLE');`. Did you also try this?
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.