Clear region with menu's per url cache

Created on 17 January 2019, almost 6 years ago
Updated 11 May 2024, 7 months ago

I have a region with menus, a menus displays depending on the url example if on the about page(sitename/about-us), display about menu and links as a sub menu.

It works, but the problem is after navigating through the site a couple of times, the region caches. is the anyway i can clear the regions cache on page reload.

I tried the below in my .theme

/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function themename_preprocess_block(&$vars) {
//the menu block id name in the region
if ($vars['derivative_plugin_id'] == 'submenu') {
//-- This stops the block being cache in drupal 8
$vars['#cache']['max-age'] = 0;

}
}
also tried

/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function themename_preprocess_block(&$vars) {
if ($vars['derivative_plugin_id'] == 'theme-block-branding') {
//-- This stops the block being cache in drupal 8
$vars['#cache']['max-age'] = 0;
}
}
not sure what steps I can follow to achieve the above

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡ΏπŸ‡¦South Africa Lloyd_87

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024