模板中的语言相关模块内容 - Drupal 8

Language Dependent Module Content in Template - Drupal 8

所以我的自定义 drupal 8 问题中有以下问题,它以某种方式与缓存发生冲突。它需要一些部分作为可翻译的字符串 (ok) 和一些来自后端服务的部分 (not ok)

我的模块数组:

 return array(
        '#theme' => 'block__vt_course_offer',
        '#data' => $courseData,
        '#cache' => [
            'contexts' => ['languages'],
            'tags' => $cacheTags,
        ]
    );

还有我模板的一部分

<!-- This works just perfect: -->{% trans %}Prüfungen{% endtrans %}
...
<div class="course-block__desc">
   <!-- This dissplays only one language at the moment of cache build: -->
   {{ course_type.short_description[language] | raw }}
</div>

有没有办法在启用缓存后以不同的语言为 {{ course_type.short_description[language] | raw }} 传递不同的值?目前它提供第一次调用的语言,当缓存被清除时,这会导致英语网站上的德语内容,反之亦然。

非常感谢您的帮助!

最后我们采用了这种方法: - 包含不缓存的小型渲染数组。