HOOK_page_alter in 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.
}

但是在Drupal 8中,我认为没有hook_page_alter

如何在Drupal 8 ??

中执行此操作

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

@see hook_preprocess_hook()和template_preprocess_page()

示例:

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']);        
}

hook_page_alter发生了什么事,请在此处的Drupal Change记录中说明,因此在您的情况下,您可能会使用hook_page_bottom。

即使您可以在主题中使用kint(),只需将主题附加在变量

最新更新