我已经在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 Drupal\calendar\Controller;
class CivilCController {
public function calendar(){
$content[] = [
//stuff here
];
$content[] = [
//stuff here
];
return [
'#theme' => 'calendar_display',
'#test' => $content,
];
}
}
现在我有一个名为calendar-template.html.twig
的树枝文件。但是,此文件在标题下方呈现。
在主题中,您应该有一个称为“标题”的区域,并且在其中应放置为该区域提供内容的块。对于每个块,您可以定义(在块首选项中)应在什么页面上显示哪些页面,而不应该在什么页面上定义。
对于更复杂的用例,您可以使用“上下文”模块:https://www.drupal.org/project/context
您不需要该功能的自定义模块。