Twig html_实体_细枝解码(opencart)

Twig html_实体_细枝解码(opencart),twig,opencart,Twig,Opencart,我试图在我的产品页面(OpenCartV3)上输出产品的属性 该属性称为“technicaldetails”,使用以下代码可以正常工作: {% if attribute_groups %} {% for attribute_group in attribute_groups %} {% if attribute_group.name == 'technicaldetails' %} {% for attribute in attribute_group.attribute

我试图在我的产品页面(OpenCartV3)上输出产品的属性

该属性称为“technicaldetails”,使用以下代码可以正常工作:

{% if attribute_groups %}
  {% for attribute_group in attribute_groups %}
    {% if attribute_group.name == 'technicaldetails' %}
      {% for attribute in attribute_group.attribute %}
        {{ attribute.text }}
      {% endfor %}
    {% endif %}
  {% endfor %}
{% endif %}
但是“技术细节”字段中存储了未设置样式的列表。。这将输出完整的html,而不是呈现列表

我试过使用
{{attribute.text | e}
{{attribute.text | raw}
以及我能找到的许多其他替代方法。。但是每次都只是抛出html而不是呈现它

在php中,这通常是可行的

<?php echo html_entity_decode($attribute['text']); ?>

既然我不能在twig中使用php,而且twig中也没有html_实体_解码,那么我现在如何解码html呢(

期待您的帮助:)

非常感谢


谢谢。

只需在
twig
中注册
html\u entity\u decode
功能即可。 最简单的方法是查看
twig
的加载位置并添加以下代码

$twig->addFilter(new \Twig_Simple_Filter, 'html_entity_decode', 'html_entity_decode');
之后,您可以在
twig
模板中执行以下操作

{{ attribute.text|html_entity_decode }}
查找文件

document_root/system/library/template/twig.php
刚过

$this->twig = new \Twig_Environment($loader, $config);
添加以下代码

$twig->addFilter(new \Twig_SimpleFilter('html_entity_decode', 'html_entity_decode'));
完成此操作后,您必须转到“管理员”在“菜单扩展->修改”中重新加载所有修改。 之后,您可以在所有twig文件*.twig中执行以下操作

{{ attribute.text|html_entity_decode }}

attribute.text作为html存储在DB中。。它被编码了,这就是为什么我使用了
html\u entity\u decode()
函数,并且它曾经工作过。。但是现在opencart使用了twig,我不知道如何解决这个问题:(它是存储为原始HTML还是编码HTML?就像当你直接查看数据库时,标签是存储为
还是
?如果答案是后者,你可能需要创建一个
htmlspecialchars\u decode
自定义twig过滤器这就是它在数据库中的方式(直接从那里复制)
  • 1
  • 2
  • 3
  • 4
    • 使用
      |raw
      应该可以工作,除非OpenCart对您正在使用的任何东西进行额外的转义。或者出于安全原因,他们不允许您尝试执行任何操作?尝试制作一个细枝过滤器并使用该
      |raw
      >给出了同样的东西。
      |e
      工作起来很有魅力!!!非常感谢!现在只需要看看如何使更新不会再次删除它:D