Drupal 8 中的 HOOK_page_alter

Nei*_*eiL 0 drupal drupal-8

我试图在每一页上附加一个树枝模板。
在 Drupal 7 中,我们基本上使用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.
}
Run Code Online (Sandbox Code Playgroud)

hook_page_alter我认为在 Drupal 8 中没有。

如何在 drupal 8 中做到这一点?

小智 5

您可以hook_preprocess_page(&$variables)在 Drupal 8 中使用来更改页面内容。

例子:

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']);        
}
Run Code Online (Sandbox Code Playgroud)