树枝的html_entity_decode(opencart) [英] html_entity_decode for twig (opencart)

查看:59
本文介绍了树枝的html_entity_decode(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆