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



我在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。

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

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

模块文件:

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

在我的控制器文件中:

namespace DrupalcalendarController;

class CivilCController {
public function calendar(){
$content[] = [
//stuff here
];
$content[] = [
//stuff here
];
return [
'#theme' => 'calendar_display',
'#test' => $content,
];
}
}

现在我有一个名为calendar-template.html.twig的树枝文件。但是,此文件在标题下方呈现。

在您的主题中,您应该有一个名为"header"的区域,您应该在其中放置为该区域提供内容的块。对于每个块,您可以定义(在块首选项中(它应该出现在哪些页面上,以及不应该出现在哪些页面上。

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

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

最新更新