【问题标题】:HOOK_page_alter in Drupal 8Drupal 8 中的 HOOK_page_alter
【发布时间】:2017-04-29 22:57:01
【问题描述】:

我正在尝试在每个页面上附加一个树枝模板。
在 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


【解决方案1】:

What happened to hook_page_alter is explained here in the Drupal change record 所以在你的情况下你可能会使用 hook_page_bottom。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      您可以在 Drupal 8 中使用 hook_preprocess_page(&amp;$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']);        
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多