0

I have a view with the following:

CONTEXTUAL FILTERS: Content: Has taxonomy term ID
FIELDS: Global: Custom text = {{ raw_arguments.tid }} 

When developing, the output of Global: Custom text = {{ raw_arguments.tid }} matches the content of CONTEXTUAL FILTERS: Content: Has taxonomy term ID

But in the cached version of the view, FIELDS: Global: Custom text = {{ raw_arguments.tid }} always displays the first value calculated after the cache has been cleared.

Ideally I am looking to add

            '#cache' => [
                'contexts' => [
                    'url.path',
                ],
            ],

to my view/block, but I am really not sure how to do this.

I have tried https://www.drupal.org/project/views_custom_cache_tag but I could not figure out the correct string to add to my view to achieve this.

  • I added Global: Rendered entity - Taxonomy term (Global: Rendered entity - Taxonomy term) – ice70 Dec 18 '18 at 13:20
  • In header or fields? With fields you run into trouble because Views caches rows and only knows the dependency on the row entity, not of data you've added through tokens. – 4k4 Dec 18 '18 at 13:25
  • sorry, ebkac. I added Global: Rendered entity - Taxonomy term (Global: Rendered entity - Taxonomy term) to my header, but it did not show anything on the front end. I checked my template and the {{ header }}} is still there. I am really just after the tid, which I am adding as a querystring to link returned in the row. So the custom text is ?ctid={{ raw_arguments.tid }} which is then used in the twig template as: {{ fields.nothing.content|render|striptags|trim }} – ice70 Dec 18 '18 at 13:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.