【问题标题】:How to add the help text of a custom module in a separate template file in Drupal 8?如何在 Drupal 8 的单独模板文件中添加自定义模块的帮助文本?
【发布时间】: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() 函数中指向该模板文件。我该怎么做?

【问题讨论】:

    标签: php module drupal-8


    【解决方案1】:

    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 }}
    

    【讨论】:

      猜你喜欢
      • 2016-10-05
      • 2017-01-01
      • 2015-08-30
      • 2016-10-05
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多