2012-06-20 82 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}