简体   繁体   English

如何更改 Drupal 9 中呈现的 Html

[英]How I can change rendered Html in Drupal 9

I created custom module and it need to be able to change rendered html of each page on the site.我创建了自定义模块,它需要能够更改网站上每个页面的渲染 html。 I wand to change all external links.我想更改所有外部链接。 How I can realize it?我怎么能意识到呢? Can I use hooks?我可以使用挂钩吗? How I can do in in right way?我怎样才能以正确的方式做?

The answer is to understand the Drupal templating system.答案是了解 Drupal 模板系统。 Any Twig template on Drupal can be overridden with the current theme by copying the Twig-template into your theme and overriding the template content.通过将 Twig 模板复制到您的主题并覆盖模板内容,可以用当前主题覆盖 Drupal 上的任何 Twig 模板。 You can also use theme_hooks with modules to override templates in modules instead of themes.您还可以将 theme_hooks 与模块一起使用来覆盖模块中的模板而不是主题。

Take a look at the documentation: https://www.drupal.org/docs/theming-drupal/twig-in-drupal/working-with-twig-templates查看文档: https://www.drupal.org/docs/theming-drupal/twig-in-drupal/working-with-twig-templates

For your specific link-Template you can use:对于您的特定链接模板,您可以使用:

  • core/modules/system/templates/links.html.twig核心/模块/系统/模板/链接.html.twig

or depending on your base theme:或取决于您的基本主题:

  • web/core/themes/classy/templates/navigation/links.html.twig web/core/themes/classy/templates/navigation/links.html.twig
  • web/core/themes/olivero/templates/navigation/links.html.twig web/core/themes/olivero/templates/navigation/links.html.twig
  • web/core/themes/stable/templates/navigation/links.html.twig web/core/themes/stable/templates/navigation/links.html.twig
  • web/core/themes/stable9/templates/navigation/links.html.twig web/core/themes/stable9/templates/navigation/links.html.twig
  • web/core/themes/starterkit_theme/templates/navigation/links.html.twig web/core/themes/starterkit_theme/templates/navigation/links.html.twig

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

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