PHP Manual

PEAR Manual

Smarty Manual

PostgreSQL

MySQL Manual

Perl Manual

chapter 5. variable modifiers

variable modifiers can be applied to variables, custom functions or strings. to apply a modifier, specify the value followed by the | (pipe) and the modifier name. a modifier may accept additional parameters that affect its behavior. these parameters follow the modifer name and are separated by : (colon).

example 5-1. modifier example

{* apply modifier to a variable *} {$title|upper} {* modifier with parameters *} {$title|truncate:40:"..."}  {* apply modifier to a function parameter *} {html_table loop=$myvar|upper} {* with parameters *} {html_table loop=$myvar|truncate:40:"..."}  {* apply modifier to literal string *} {"foobar"|upper}  {* using date_format to format the current date *} {$smarty.now|date_format:"%y/%m/%d"}  {* apply modifier to a custom function *} {mailto|upper address="me@domain.dom"}

if you apply a modifier to an array variable instead of a single value variable, the modifier will be applied to every value in that array. if you really want the modifier to work on an entire array as a value, you must prepend the modifier name with an @ symbol like so: {$articletitle|@count} (this will print out the number of elements in the $articletitle array.)

modifiers can be autoloaded from your $plugins_dir (also see: naming conventions) or can be registered explicitely (see: register_modifier).

additionally all php-functions can be used as modifiers implicitly. (the @count example above actually uses php's count() function and not a smarty-modifier). using php-functions as modifiers has two little pitfalls: first: sometimes the order of the function-parameters is not the desirable one ({"%2.f"|sprintf:$float} actually works, but asks for the more intuitive. for example:{$float|string_format:"%2.f"} that is provided by the smarty distribution). second: with $security turned on all php-functions that are to be used as modifiers have to be declared trusted in the $security_settings['modifier_funcs']-array.

see also register_modifier(), register_function(), extending smarty with plugins and modifiers,

capitalize

this is used to capitalize the first letter of all words in a variable.

parameter positiontyperequireddefaultdescription
1booleannofalsethis determines whether or not words with digits will be uppercased

example 5-2. capitalize

<?php

$smarty
->assign('articletitle''next x-men film, x3, delayed.');

?>

where template is:

{$articletitle} {$articletitle|capitalize} {$articletitle|capitalize:true}

this will output:

next x-men film, x3, delayed. next x-men film, x3, delayed. next x-men film, x3, delayed.

see also lower and upper