如何使用分类法对分类法术语 drupal 8 进行主题化-term.html.twig
How to theme taxonomy terms drupal 8 using taxonomy-term.html.twig
我需要使用一个模板为所有学期的所有页面设置主题。我尝试这样做,并创建分类法-term.html.twig,清除缓存,但它不起作用。我要做什么?
现在我找到了这个(https://drupal.stackexchange.com/questions/217850/how-to-make-page-html-twig-based-on-vocabulary),但它是为每个术语分别设置主题的。我想我需要相同的代码,但所有条款都需要一个文件。
您可能将 taxonomy-term.html.twig
文件放在 Drupal 不会查找的目录中。查看 https://www.drupal.org/docs/8/theming-drupal-8/drupal-8-theme-folder-structure 以了解有关允许的地点的更多信息。
如果启用 twig 调试,您可以看到 Drupal 加载了哪个文件。您可以关注此页面:https://befused.com/drupal/twig-debug。
本质上,启用调试后,通过浏览器查看站点的源代码。 Twig 已添加 HTML 评论它查找和加载的文件。
为了使主题更容易,我强烈建议停用渲染缓存。来自 https://www.drupal.org/node/1903374:
To disable the render cache, add the following lines to either:
settings.php, taking care not to add it to your production site
or settings.local.php, by uncommenting the lines at the bottom of your settings.php first.
These lines are:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
Drupal 8 默认使用 Views 模块呈现分类术语。
要解决这个问题,只需禁用名为 分类术语 (machine name: taxonomy_term
).
的视图
一旦禁用,Drupal 8 将使用 taxonomy-term.html.twig
.
呈现每个分类术语页面
我需要使用一个模板为所有学期的所有页面设置主题。我尝试这样做,并创建分类法-term.html.twig,清除缓存,但它不起作用。我要做什么? 现在我找到了这个(https://drupal.stackexchange.com/questions/217850/how-to-make-page-html-twig-based-on-vocabulary),但它是为每个术语分别设置主题的。我想我需要相同的代码,但所有条款都需要一个文件。
您可能将 taxonomy-term.html.twig
文件放在 Drupal 不会查找的目录中。查看 https://www.drupal.org/docs/8/theming-drupal-8/drupal-8-theme-folder-structure 以了解有关允许的地点的更多信息。
如果启用 twig 调试,您可以看到 Drupal 加载了哪个文件。您可以关注此页面:https://befused.com/drupal/twig-debug。 本质上,启用调试后,通过浏览器查看站点的源代码。 Twig 已添加 HTML 评论它查找和加载的文件。
为了使主题更容易,我强烈建议停用渲染缓存。来自 https://www.drupal.org/node/1903374:
To disable the render cache, add the following lines to either: settings.php, taking care not to add it to your production site or settings.local.php, by uncommenting the lines at the bottom of your settings.php first. These lines are:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
Drupal 8 默认使用 Views 模块呈现分类术语。
要解决这个问题,只需禁用名为 分类术语 (machine name: taxonomy_term
).
一旦禁用,Drupal 8 将使用 taxonomy-term.html.twig
.