树枝的html_entity_decode(opencart) [英] html_entity_decode for twig (opencart)
问题描述
im试图在我的产品页面(opencart v3)上输出产品的属性.
im trying to output an attribute of a product on my product page (opencart v3).
该属性称为"technicaldetails",使用以下代码即可正常工作:
The attribute is called 'technicaldetails' and it works just fine using this code:
{% 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而不是呈现列表.
but the technical details field have unstyled list stored in it.. and this outputs the complete html instead of rendering the list.
ive尝试使用{{ attribute.text|e }}
和{{ attribute.text|raw }}
以及其他许多我可以找到的替代方法..但是每次只是抛出html而不渲染它..
ive tried using {{ attribute.text|e }}
and {{ attribute.text|raw }}
and many other alternatives i could find.. but each time is just throws out the html and not render it..
在php中,这曾经可以工作.
in php this used to work.
<?php echo html_entity_decode($attribute['text']); ?>
所以我现在该如何解码html,因为我不能在树枝中使用php,并且在树枝中也没有html_entity_decode:(
so how can i decode the html now as i cant use php in twig and there is no html_entity_decode in twig either :(
期待一些帮助:)
非常感谢
谢谢.
推荐答案
只需在twig
中注册html_entity_decode
函数.
最简单的方法是查看twig
的加载位置并添加以下代码
Just register the html_entity_decode
function in twig
.
The most simple way is to look where twig
is loaded and add the following code,
$twig->addFilter(new \Twig_Simple_Filter, 'html_entity_decode', 'html_entity_decode');
之后,您只需在twig
模板中执行以下操作
After that you can just do the following in your twig
templates
{{ attribute.text|html_entity_decode }}
这篇关于树枝的html_entity_decode(opencart)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!