drupaldrupal-8

HOOK_page_alter in Drupal 8


I am trying to append a twig template on every page.
In Drupal 7, we basically append it using hook_page_alter

function hook_page_alter(&$page) { 
  $page['page_bottom']['devel']= array(
    '#type' => 'markup',
    '#markup' => '<div style="clear:both;">' . theme('TEST') . '</div>',
  ); // add test template on every page at bottom position.
}

but in Drupal 8 there is no hook_page_alter I think.

How to do this in drupal 8??


Solution

  • You can use hook_preprocess_page(&$variables) in Drupal 8 to alter page content.

    Example:

    function bartik_preprocess_page(&$variables){
    
       $variables['page']['footer_fourt']['test']= array( 
            '#type' => 'markup', 
            '#markup' => '<div style="clear:both;">hello test</div>', );
       kint($variables['page']['footer_fourt']['test']);        
    }