2016-12-14 35 views
0

我想在每個頁面上附加一個樹枝模板。
在Drupal 7的,我們基本上都採用hook_page_alterHOOK_page_alter in Drupal 8

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中做到這一點?你需要的是在這裏

回答

2

您可以使用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']);   
} 
0

甚至可以在主題使用編制品()只是附上主題變量