Invenzzia »

Custom escaping functions

From Invenzzia wiki

Jump to: navigation, search

Open Power Template provides you a convenient way to escape the HTML from the template variables using modifiers:

<p>{e:$variable} <!-- this variable will be escaped --></p>
<p>{u:$variable} <!-- this will not --></p>

The escaping can be done automatically, depending on the global OPT or template settings. However, by default it uses only a simple htmlspecialchars() function. Fortunately, there is a very easy way to install a custom escaping function, so you can use more powerful XSS filters directly in OPT. All you have to do is to register your filter function in OPT under the name escape:

function myAwesomeFilter($text)
{
// do some magic here
return $text;
} // end myAwesomeFilter();
 
$tpl->register(Opt_Class::PHP_FUNCTION, 'escape', 'myAwesomeFilter');
Personal tools