Drupal 8 中的 HOOK_page_alter

问题描述 投票:0回答:3

我正在尝试在每个页面上附加一个树枝模板。
在 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 drupal-8
3个回答
6
投票

您可以在 Drupal 8 中使用

hook_preprocess_page(&$variables)
来更改页面内容。

示例:

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

1
投票

hook_page_alter 发生的情况在 Drupal 更改记录中进行了解释,因此在您的情况下,您可能会使用 hook_page_bottom。


-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.