有没有办法像默认一样在php smarty中使用strip_tags来允许特定的html标签通过?
stip_tags($a.message,'<p><div>');
在 Smarty 中等价物是什么?
{$a.message|strip_tags}
我正在使用 Smarty 2.6.26,strip_tags
使用指定要保留哪些标签的参数。
试试这个:
.PHP:
$string = "<b>not bold</b><iframe>iframe goes away</frame> <p>paragraphed</p>
<div style='color:green'>div kept.</div>";
$smarty->assign('string', $string);
在模板中:
{$string|strip_tags:"<p><div>"}
<p>
和<div>
不会被剥离。
我知道
我有点晚了,但对于那些需要这样做并且不想编写 Smarty 插件的人:
在 Smarty 中,你可以从 PHP 中"借用"方法,就像这样。
而不是:
{$a.message|strip_tags}
用
{strip_tags($a.message,"<br><div>") nofilter}
注意:如果您设置了 nofilter 参数$smarty->escape_html = true;
则只需要 nofilter 参数
根据文档,无法指定要保留的标签。但是,您可以轻松地为自己创建一个插件:http://www.smarty.net/docs/en/plugins.writing.tpl