Skip to content

Instantly share code, notes, and snippets.

@crittermike
Last active October 23, 2020 17:43
Show Gist options
  • Save crittermike/149db0058375a8eba3bffcc878e73d48 to your computer and use it in GitHub Desktop.
Save crittermike/149db0058375a8eba3bffcc878e73d48 to your computer and use it in GitHub Desktop.
Add a query_args cache context to the header block so that the cache is dependent on query string.
<?php
function MODULENAME_block_build_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
// Add the 'query args' cache context to the header block.
if ($this_block_is_the_header_block) { // @TODO: Make this line work.
$build['#cache']['contexts'][] = 'url.query_args';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment