簡體   English   中英

Drupal 8 定制模塊 - 定制 header

[英]Drupal 8 custom module - custom header

我在 Drupal 8 中創建了一個自定義模塊。我希望自定義模塊顯示自定義 header 而不是所有其他頁面上顯示的標准模塊。

我使用此處找到的文檔創建了自定義 twig 模板: https://www.drupal.org/docs/8/theming-for-create-module/docs.twig-templates-custom-module/ 我也以此為參考: https://www.drupal.org/forum/support/module-development-and-code-questions/2017-05-15/drupal-8-custom-module-template

我能夠創建模板,但是該模板似乎在 header 模板之后和頁腳模板之前被調用和渲染。 因此,使用文檔我無法更改 header 文件中的任何內容。

關於如何為我的自定義模塊創建自定義 twig 文件的任何想法? 以下是我的代碼片段:

模塊文件:

function calendar_theme($existing, $type, $theme, $path) {
    return array(
        'calendar_display' => array(
            'variables' => array('test' => NULL),
            'template' => 'calendar-template',
        ),
    );
}

在我的 controller 文件中:

namespace Drupal\calendar\Controller;


class CivilCController {

    public function calendar(){

        $content[] = [
            //stuff here
        ];

        $content[] = [
            //stuff here
        ];

        return [
            '#theme' => 'calendar_display',
            '#test' => $content,
        ];

    }

}

現在我有一個名為calendar-template.html.twig的 twig 文件。 但是,此文件在 header 下方呈現。

在您的主題中,您應該有一個名為“標題”的區域,並且在其中您應該放置為該區域提供內容的塊。 對於每個塊,您可以定義(在塊首選項中)它應該出現的頁面和不應該出現的頁面。

對於更復雜的用例,您可以使用Context模塊:

您不需要該功能的自定義模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM