Drupal 8 菜单项标题,里面有 HTML,里面有 TWIG



我只想将菜单项标题的一部分包装在一个强元素中:

<a href="page">Learn <strong>more</strong></a>

但是Drupal正在逃避强元素,所以它看起来像这样

学习<强>更多

如何禁用 twig 文件中 html 的转义?这是我的菜单.html.twig :

{% macro menu_links(items, attributes, menu_level, classes) %}
  {% if items %}
    <div{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}>
    {% for item in items %}
      {%
        set item_classes = [
          item.is_expanded and item.below ? 'expanded',
          item.is_expanded and menu_level == 0 and item.below ? 'dropdown',
          item.in_active_trail ? 'active',
        ]
      %}
      {% autoescape %}
        {{ link(item.title, item.url)|raw }}
      {% endautoescape %}
    {% endfor %}
  </div>
  {% endif %}
{% endmacro %}
{{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class]) }}

编辑:更新了树枝代码,使用了我最有希望的解决方法尝试。仍然没有爱情:(

{{ link(item.title, item.url)|raw }}替换为

<a href="{{item.url}}">{{item.title|raw}}</a>

在变量中设置链接标题,然后在树枝链接函数中传递 thaat 变量。

{% set link_text %}{{ item.title|raw }}{% endset %}
{{ link(link_text, item.url) }}  

最新更新