【问题标题】:Language Dependent Module Content in Template - Drupal 8模板中的语言相关模块内容 - Drupal 8
【发布时间】:2016-12-19 22:41:17
【问题描述】:

所以我在我的自定义 drupal 8 问题中有以下问题,它在某种程度上与缓存冲突。它需要一些部分作为可翻译的字符串(好的)和来自后端服务的一些部分(不好)

我的模块数组:

 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 }} 提供不同的值?目前它使用第一次调用的语言,当缓存被清除时,这会导致英文网站上的德语内容,反之亦然。

非常感谢您的帮助!

【问题讨论】:

标签: caching drupal drupal-8


【解决方案1】:

最后我们采用了这种方法:https://stackoverflow.com/a/42225791/2776727 - 包含不缓存的小型渲染数组。

【讨论】:

    猜你喜欢
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多