Benn
Benn

Reputation: 5023

Php smarty strip_tag allow specific tags

Is there any way to use strip_tags in php smarty like in default , to allow specific html tags to pass?

stip_tags($a.message,'<p><div>');

what is the equivalent in smarty ?

{$a.message|strip_tags}

Upvotes: 3

Views: 9211

Answers (3)

Fred
Fred

Reputation: 41

I know I'm a bit late, but for those who needs to do this and don't want to write a Smarty-plugin:

In Smarty you can "borrow" methods from PHP, like this.

Instead of:

{$a.message|strip_tags}

use

{strip_tags($a.message,"<br><div>") nofilter}

Note: You only need the nofilter argument if you've set $smarty->escape_html = true;

Upvotes: 4

chilyashev
chilyashev

Reputation: 143

I'm using Smarty 2.6.26 and strip_tags works with an argument specifying which tags to keep.

Try this:

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);

In the template:

{$string|strip_tags:"<p><div>"}

<p> and <div> will not be stripped.

Upvotes: 5

DavidS
DavidS

Reputation: 1690

According to the documentation, it is not possible to specify which tags to keep. However, you can easily create a plugin for yourself: http://www.smarty.net/docs/en/plugins.writing.tpl

Upvotes: 2

Related Questions