Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add a query_args cache context to the header block so that the cache is dependent on query string.
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