I have a complex variable {{course_type.title[language] | nl2br}}
in my custom block template. language
is the current sites language but the content is only delivered in the language of the time, when the cache was build.
I do have languages in my render array and it works for {% trans %}
commands in the twig template:
return array(
'#theme' => 'block__vt_course_offer',
'#data' => $courseData,
'#cache' => [
'contexts' => ['languages'],
'tags' => $cacheTags,
]
);
Is there a way to get Drupal to handle multiple cache entries based on the current language of the page?
Thx a lot!
Andreas
So we found a solution for this - we extracted the different parts into sub render arrays and dissabled the cache only for them. Important is, that the access to data[$language] is happening in the main module, not in the template.
Then we can use it in the twig as:
In a nutshell it boils down to the template usage of
{{variable.preset_language_value}}
instead of{{variable.value[language]}}