For my view I need to update my fields dynamically, for this reason I need to disable cache for views-view-field.html.twig, as it takes the parameter from a contextual filter.
I send an argument from template_preprocess_views_view_field() to the template file.

I know how to disable the caching of template files for developers, but I cannot use it on the production system, as it may affect the performance. So the issue for me is disabling the cache only for a single template.


I believe you can use the value of your field to set a custom cache tag in your view, that should invalidate the cache whenever your field value changes.

template_preprocess_views_view_field(&$variables) {
  $view = $variables['view'];
  $parameter = 'my_custom_field_that_is_sent_as_argument_to_twig';
  $view->element['#cache']['tags']['custom_parameter:' . $parameter];

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.