【发布时间】:2017-12-21 13:53:35
【问题描述】:
按照此文档https://www.drupal.org/docs/8/creating-custom-modules/basic-structure,在 Drupal 8 中创建自定义模块时,可以在 my_custom_module.module 文件中的 hook_help() 函数中添加帮助文本。
我想将帮助文本放在一个单独的模板文件中,并在 hook_help() 函数中指向该模板文件。我该怎么做?
【问题讨论】:
按照此文档https://www.drupal.org/docs/8/creating-custom-modules/basic-structure,在 Drupal 8 中创建自定义模块时,可以在 my_custom_module.module 文件中的 hook_help() 函数中添加帮助文本。
我想将帮助文本放在一个单独的模板文件中,并在 hook_help() 函数中指向该模板文件。我该怎么做?
【问题讨论】:
hook_help() 返回一个可渲染的数组,因此您可以为此使用custom theme and template:
function help_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'your.custom.route':
return ['#theme' => 'my_custom_theme'];
}
}
不要忘记在你的树枝模板中使用t 函数来支持翻译:
{{ "My string"|t }}
【讨论】: