2017-08-31 117 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