html_entity_decode 用于树枝 (opencart)
html_entity_decode for twig (opencart)
我正在尝试在我的产品页面 (opencart v3) 上输出产品的属性。
该属性称为 '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']); ?>
所以我现在如何解码 html 因为我不能在 twig 中使用 php 而且 twig 中也没有 html_entity_decode :(
期待一些帮助:)
非常感谢
谢谢。
只需在twig
中注册html_entity_decode
函数即可。
最简单的方法是查看twig
加载的位置并添加以下代码,
$twig->addFilter(new \Twig_Simple_Filter, 'html_entity_decode', 'html_entity_decode');
之后,您只需在 twig
模板中执行以下操作
{{ attribute.text|html_entity_decode }}
更新: 对于 Opencart 3.0.3.7 版本过滤器应该是这样的:
$twig->addFilter(new \Twig\TwigFilter('html_entity_decode','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
{{ attribute.text|html_entity_decode }}
我正在尝试在我的产品页面 (opencart v3) 上输出产品的属性。
该属性称为 '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']); ?>
所以我现在如何解码 html 因为我不能在 twig 中使用 php 而且 twig 中也没有 html_entity_decode :(
期待一些帮助:)
非常感谢
谢谢。
只需在twig
中注册html_entity_decode
函数即可。
最简单的方法是查看twig
加载的位置并添加以下代码,
$twig->addFilter(new \Twig_Simple_Filter, 'html_entity_decode', 'html_entity_decode');
之后,您只需在 twig
模板中执行以下操作
{{ attribute.text|html_entity_decode }}
更新: 对于 Opencart 3.0.3.7 版本过滤器应该是这样的:
$twig->addFilter(new \Twig\TwigFilter('html_entity_decode','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
{{ attribute.text|html_entity_decode }}