我正在尝试在每个页面上附加一个树枝模板。
在 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)
来更改页面内容。
示例:
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 更改记录中进行了解释,因此在您的情况下,您可能会使用 hook_page_bottom。
即使你可以在主题中使用kint(),只需将你的主题附加到变量中