Over a million developers have joined DZone.

Smarty and escaping user input (for lazy guys)

DZone's Guide to

Smarty and escaping user input (for lazy guys)

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

Smarty gives us a simple way to escape “dirty” variables when they come to template processing. With escape variable modifier you can make “dirty” things look smart. You can escape or even remove html tags and special characters.

Variable in a Smarty template without escaping {$articleTitle}
and with escaping {$articleTitle|escape:'html'}

But if you are lazy like me you might wonder what the need to write “escape:’html’” again and again for all variables. Good new is that we can make Smarty do it by default by setting $default_modifiers field for Smarty object. For lazy guys here is sample

$smarty->default_modifiers = array('escape:"html"');

We can turn off this “defaul” behaviour for selected variables with

Be Smarty and good luck! :)

Take a look at an Indigo.Design sample application to learn more about how apps are created with design to code software.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}