Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

View the Project on GitHub smarty-php/smarty

Variable Modifiers

Table of contents

Variable modifiers can be applied to variables, custom functions or strings. To apply a modifier, specify the value followed by a | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifier name and are separated by a : (colon). Also, all php-functions can be used as modifiers implicitly (more below) and modifiers can be combined.

{* apply modifier to a variable *}

{* modifier with parameters *}

{* apply modifier to a function parameter *}
{html_table loop=$myvar|upper}

{* with parameters *}
{html_table loop=$myvar|truncate:40:"..."}

{* apply modifier to literal string *}

{* using date_format to format the current date *}

{* apply modifier to a custom function *}
{mailto|upper address=""}

{* using  php's str_repeat *}

{* php's count *}

{* this will uppercase and truncate the whole array *}
<select name="name_id">
{html_options output=$my_array|upper|truncate:20}

See also registerPlugin(), combining modifiers. and extending smarty with plugins