S
S
slun2017-06-08 13:23:33
Drupal
slun, 2017-06-08 13:23:33

How to disable block-level caching or how to display dynamic information in Drupal 8?

In particular, there is a system-branding-block, I need to display the current page title in it and, accordingly, disable it in the page block. With the second one, everything is simple - redefine the template (although maybe there are some more correct methods?)
But what about the first one? In my own topic, I give this hook:

function mytheme_preprocess_block(&$vars) {
    if ($vars['plugin_id'] != 'system_branding_block') return; 
#Если текущий блок не system branding ничего не делаем, иначе берем тайтл от текущей ноды.

    $node = $node = \Drupal::routeMatch()->getParameter('node');
    if (!$node) return;
    $vars['page_title'] = $node->get('title')->getValue()[0]['value'];
}

But it is executed exactly once, until this block is cached with the first (after clearing the cache) page title.
Question: how to get around this?
So far, it comes to mind to get rid of the system-branding block completely and include all its contents in the html rendering template. But this is quite a crutch.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afi13, 2017-06-08
@slun

Good afternoon,
"Site branding" block is designed to display general information: site name, logo, slogan, etc.
It seems to me that you are using it for other purposes, tk. there is a Page title block for that. But the problem can be solved by adding the 'url' context block to the cache, or completely disabling the cache of your block.
https://www.drupal.org/docs/8/api/cache-api/cache-...
drupal.ru/node/127211

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question