show a smarty variable with html content

微笑、不失礼 提交于 2019-12-23 09:33:33

问题


I have a smarty variable with html content in it like: $html="<strong>Content</strong><br/>etc etc" . I try to show it html-formatted. When showing it like {$html} only plain text appears without formatting. I try like: {$html|unescape} but then the tags are shown but not applied. Do you have any suggestions?


回答1:


You should try this:

{$html|unescape:'html'}

Also check manual:

http://www.smarty.net/docs/en/language.modifier.unescape.tpl




回答2:


Interestingly, none of the answers here work with Smarty 3.1.21 on CS-Cart 4.3.4. So, just to add another thought in that circumstance, use the nofilter on the $html string like so:

{$html nofilter}




回答3:


You can try this:

{$html|unescape: "html" nofilter}



回答4:


you can try :

php function symbol:

function html($str) {
    $arr = array(
        "&lt;"      => "<",
        "&gt;"      => ">",
        "&quot;"    => '"',
        "&amp;"     => "&",
        "&#92;"     => chr(92),
        "&#39"      => chr(39),
        "&#039;"    => chr(39)
    );
    return nl2br(strtr($str,$arr));
}

In smarty template call:

{html({$html})}

Or without php function only smarty:

{$html|unescape:'allhtml'}

Notice: if in tpl have use reset css you can try remove it and try again.




回答5:


Some versions of smarty unescape is not available. If this is the case, try using escape:'htmlentitydecode'.

{$html|escape:'htmlentitydecode'}


来源:https://stackoverflow.com/questions/16449583/show-a-smarty-variable-with-html-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!