首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用hook_theme_suggestions_HOOK应用建议的主题钩子?

如何使用hook_theme_suggestions_HOOK应用建议的主题钩子?
EN

Drupal用户
提问于 2018-09-13 08:26:26
回答 2查看 737关注 0票数 1

这个答案之后,我试图使用钩子_主题_建议_钩子覆盖core/themes/seven/templates/node-add-list.html.twig

因此,我在modules/custom/domain_filter/domain_filter.module中添加了以下函数

代码语言:javascript
复制
function domain_filter_theme_suggestions_node_add_list(array $variables) {
  $suggestions = [];
  $suggestions[] = 'node_add_list__' . 'custom';
  return $suggestions;
}

我在我的模块中创建了自定义小枝文件:modules/custom/domain_filter/templates/node-add-list--custom.html.twig

这个建议在主题调试中看上去很好,但没有应用( xnode-add-list.html.twig前面):

代码语言:javascript
复制

如何应用node-add-list--custom.html.twig

EN

回答 2

Drupal用户

回答已采纳

发布于 2018-09-13 09:39:52

最后我找到了文件中的一段。在使用模块时,我们需要使用HOOK_theme()注册模板。因此,我在modules/custom/domain_filter/domain_filter.module中添加了以下函数

代码语言:javascript
复制
/**
 * Implements hook_theme().
 */
function domain_filter_theme() {
  return [
    'node_add_list__custom' => [
      'base hook' => 'node_add_list',
    ],
  ];
}

然后,我的定制模板modules/custom/domain_filter/templates/node-add-list--custom.html.twig现在被应用了。

票数 3
EN

Drupal用户

发布于 2018-09-13 08:30:12

你需要添加你的主题

代码语言:javascript
复制
themes/yourtheme/templates/node-add-list--custom.html.twig
票数 1
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/269254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档