显示带有 html 内容的 smarty 变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16449583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:13:08  来源:igfitidea点击:

show a smarty variable with html content

htmlsmarty

提问by user985409

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?

我有一个在它的HTML内容就像一个智者变量: $html="<strong>Content</strong><br/>etc etc"。我尝试以 html 格式显示它。当显示它时, {$html}只出现没有格式的纯文本。我尝试像: {$html|unescape}但是标签显示但未应用。你有什么建议吗?

回答by dhaupin

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 nofilteron the $htmlstring like so:

有趣的是,这里的所有答案都不适用于 CS-Cart 4.3.4 上的 Smarty 3.1.21。所以,只是在这种情况下添加另一个想法,像这样nofilter$html字符串上使用:

{$html nofilter}

{$html nofilter}

回答by Paulius Mar?iukaitis

You should try this:

你应该试试这个:

{$html|unescape:'html'}

Also check manual:

还要检查手册:

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

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

回答by Sim1-81

You can try this:

你可以试试这个:

{$html|unescape: "html" nofilter}

回答by Aaron Hinni

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

某些版本的 smartyunescape不可用。如果是这种情况,请尝试使用escape:'htmlentitydecode'.

{$html|escape:'htmlentitydecode'}

回答by IT Vlogs

you can try :

你可以试试 :

php function symbol:

php函数符号:

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:

在 smarty 模板调用中:

{html({$html})}

Or without php function only smarty:

或者没有 php 功能,只有 smarty:

{$html|unescape:'allhtml'}

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

注意:如果在 tpl 中有使用,reset css您可以尝试将其删除并重试。