【发布时间】:2013-05-03 05:01:21
【问题描述】:
我有一个 smarty 变量,其中包含 html 内容,例如:
$html="<strong>Content</strong><br/>etc etc"
.
我尝试以 html 格式显示它。当显示它像
{$html}
只有纯文本出现,没有格式化。我尝试喜欢:
{$html|unescape}
但随后标签显示但未应用。你有什么建议吗?
【问题讨论】:
我有一个 smarty 变量,其中包含 html 内容,例如:
$html="<strong>Content</strong><br/>etc etc"
.
我尝试以 html 格式显示它。当显示它像
{$html}
只有纯文本出现,没有格式化。我尝试喜欢:
{$html|unescape}
但随后标签显示但未应用。你有什么建议吗?
【问题讨论】:
你应该试试这个:
{$html|unescape:'html'}
同时查看手册:
http://www.smarty.net/docs/en/language.modifier.unescape.tpl
【讨论】:
你可以试试:
php函数符号:
function html($str) {
$arr = array(
"<" => "<",
">" => ">",
""" => '"',
"&" => "&",
"\" => chr(92),
"'" => chr(39),
"'" => chr(39)
);
return nl2br(strtr($str,$arr));
}
在 smarty 模板调用中:
{html({$html})}
或者没有php函数只有smarty:
{$html|unescape:'allhtml'}
注意:如果在 tpl 中有使用reset css,您可以尝试将其删除并重试。
【讨论】:
某些版本的 smarty unescape 不可用。如果是这种情况,请尝试使用escape:'htmlentitydecode'。
{$html|escape:'htmlentitydecode'}
【讨论】:
有趣的是,这里的答案都不适用于 CS-Cart 4.3.4 上的 Smarty 3.1.21。所以,只是为了在这种情况下添加另一个想法,在$html 字符串上使用nofilter,如下所示:
{$html nofilter}
【讨论】:
你可以试试这个:
{$html|unescape: "html" nofilter}
【讨论】:
使用Smarty 2.x的用户,unescape方法不可用,可以试试这个;
{$html|html_entity_decode}
【讨论】: