2017-08-31 119 views
2

即时尝试输出产品的属性在我的产品页面(opencart v3)。html_entity_decode为小枝(opencart)

属性被称为“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,因为我不能在树枝使用PHP并且在树枝没有html_entity_decode要么:(

期待着somehelp :)

大加赞赏

谢谢。

+0

以下的attribute.text存储在数据库作为一个HTML ..它得到编码这就是为什么我使用'html_entity_decode()'功能,并用于工作..但现在opencart使用树枝,我不知道一种方法来解决这个问题:( – mpixelz

+0

它存储为原料HTML还是编码HTML?就像当你直接查看数据库一样,标签存储为'<>'或'< >'?如果答案是后者,你可能需要创建一个'htmlspecialchars_decode'定制枝条筛选 –

+0

这是它是如何在数据库中(直接从那里复制) ''' ''' – mpixelz

回答

1

只需在twig注册html_entity_decode函数。 最简单的方法就是看哪里twig被加载并添加以下代码,

$twig->addFilter(new \Twig_Simple_Filter', 'html_entity_decode', 'html_entity_decode')); 

这样做后,你才可以做twig

{{ attribute.text|html_entity_decode }} 
+0

像一个魅力工作!非常感谢!现在只需要看看如何使更新不会再次删除它:D – mpixelz