繁体   English   中英

Drupal 8/9 使用自定义模块覆盖树枝

[英]Drupal 8/9 Override twig with custom module

我已经尝试了所有我发现的方法来修改 views_view_field,从官方文档开始 我还为钩子 HOOK_theme(带和不带参数“路径”、“基本钩子”)和 HOOK_theme_registry_alter 尝试了多种方法和参数,但我仍然无法在我的模块中制作树枝来覆盖原来的。

为了让事情更简单,我在没有任何自定义主题的情况下进行测试,在 /templates 下没有任何文件夹,并且我尝试修改的视图链接在管理页面内。 树枝建议阐明显示的树枝是“稳定”主题之一。

主题中的模板优先于模块中的模板,因此您需要实现HOOK_theme_registry_alter以强制 Drupal 从模块的文件夹中获取模板。

/**
 * Implements hook_theme_registry_alter().
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  // Replace the path to the registered template so that Drupal looks for
  // it in your module's templates folder.
  $theme_registry['views_view_field']['path'] = drupal_get_path('module', 'mymodule') . '/templates';
}

确保清除缓存以强制更新主题注册表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM