Drupal 8自定义模块-自定义标头

时间:2019-10-10 20:34:44

标签: php drupal twig drupal-8 drupal-modules

我已经在Drupal 8中创建了一个自定义模块。我希望该自定义模块显示一个自定义标头,而不是其他所有页面上显示的标准标头。

我已经使用以下文档创建了自定义的树枝模板:https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-for-custom-module。我也以此为参考:https://www.drupal.org/forum/support/module-development-and-code-questions/2017-05-15/drupal-8-custom-module-template

我能够创建模板,但是该模板似乎在页眉模板之后和页脚模板之前被调用并呈现。因此,有了文档,我无法更改头文件中的任何内容。

关于如何为自定义模块的标头创建自定义树枝文件的任何想法?以下是我的代码段:

模块文件:

TYPEFLAG_PREDECLID

在我的控制器文件中:

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

现在我有一个名为namespace Drupal\calendar\Controller; class CivilCController { public function calendar(){ $content[] = [ //stuff here ]; $content[] = [ //stuff here ]; return [ '#theme' => 'calendar_display', '#test' => $content, ]; } } 的树枝文件。但是,此文件在标题下方呈现。

1 个答案:

答案 0 :(得分:0)

在您的主题中,应该有一个名为“ header”的区域,并且在其中应放置为该区域提供内容的块。对于每个块,您可以(在块首选项中)定义应该在哪些页面上显示哪些页面,而不应该在哪些页面上定义。

对于更复杂的用例,您可以使用Context模块:

该功能不需要自定义模块。