繁体   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