2012-06-20 147 views
2

如何摆脱Smarty块中的HTML标签?
我试过{strip}块内,它没有工作。
另外我试着写一个插件。但是,我怎样才能解析一个块的内容到一个字符串变量?摆脱Smarty块中的HTML标签

回答

2

{strip}块实际上做了别的事 - 它只剥去标记的空白。

你可以写一个简单的块插件:

function smarty_block_sanitize($parms, $content, &$smarty, &$repeat) { 
    if($repeat) { 
     return(strip_tags($content)); 
    } 
} 

将这个地方在PHP文件显示模板之前调用。要在模板中使用它,这样做:

Sample text {sanitize}<more markup>test</more markup>{/sanitize} End text. 

谨防允许与strip_tags的标签(其PHP参数),因为的onclick /的onmouseover /其他邪恶的属性没有得到过滤。

0

您可以{capture}一个变量块,然后用它PHP的strip_tags()

{capture name="withtags"} 
    <em>Text</em> with <strong>tags</strong> 
{/capture} 
{$smarty.capture.withtags|strip_tags}