Language Dependent Module Content in Template - Drupal 8

59 views Asked by At

so I have the following Issue in my custom drupal 8 issue, which is somehow collifing with the cache. It takes some parts as translatable strings (ok) and some parts from a backend service (not ok)

My module array:

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

And part of my template

<!-- 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>

Is there a way to deliver for {{ course_type.short_description[language] | raw }} different values in different languages when the cache is enabled? At the moment it dlivers th language of the first call, when the cache was cleared, whcih leads to german content on an english site or vise versa.

Thx a lot for your help!

1

There are 1 answers

0
Andreas On BEST ANSWER

In the end we went for this approach: https://stackoverflow.com/a/42225791/2776727 - to include small render arrays, which are not cached.