Score:2

get the value of a drupal token inside a twig code

pl flag

does anybody knows how to get the value of a drupal token inside a twig code(global text field) block in the views's header? I can get the value of the token outside the twig code block, but not inside ...

[view:page-count]/*token works outside*/

{% set count = [view:page-count]  %} /*does NOT work*/
{% if count == 1 %}
    <p class="text-danger">Atención: en esta región sólo debe haber un artículo  </p>
{% endif %}

greetings

4uk4 avatar
cn flag
So you have both, token replacement and twig available? Still, you need to consider the Twig syntax after token replacement. See https://drupal.stackexchange.com/questions/259534/what-is-the-replacement-pattern-in-rewrite-ouput-for-current-user-id
Jorge Luis Arzola avatar
pl flag
thanks, I found the solution there: I had to enclose the drupal token in apostrophes, but apart from that I had to create a special text filter using the contrib module [Twig input filter](https://www.drupal.org/project/twig) to be able to use full twig code in Global text area.
Score:1
pl flag

Enclosing the token in apostrophes solved the problem, but apart from that I had to create a special text filter using the contrib module Twig input filter to be able to use full twig code in a views Global text area.

As it seems, Global text area with minimal filtering(also availeble in views), which I was using, does NOT fully support twig.

[view:page-count]/*token works outside*/

{% set count = '[view:page-count]'  %} /* this WORKS inside*/
{% if count == 1 %}
    <p class="text-danger">Atención: en esta región sólo debe haber un artículo  </p>
{% endif %}
I sit in a Tesla and translated this thread with Ai:

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.