Skip to main content
Category:

Code snippet that can be used to pass variable to html.html.twig in Drupal 8.

/**
 * @param $variables
 */
function mymodule_preprocess_html(&$variables)
{
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node) {
        $variables['node_id'] = 'node-' . $node->id();
    }
}

Print the value in html.html.twig like this: 

{{ node_id }}

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook