I have added a views block through my twig template file (page.html.twig) through Twig_tweaks. It looks like this {{ drupal_view('view_name', 'block_name') }}.

I would like to disable caching for that particular block, but changes to the preprocess_views_view, seem to have no effect. Any suggestions to disable caching for just this one views block?

Any help very much appreciated.


You can use

function hook_block_view_BASE_BLOCK_ID_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
  //Change the title of the specific block.
  $build['#cache']['max-age'] = 0;

Also note that this does not disable the page cache for anonymous users. If you need that too, then you also need:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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