default modifier in smarty

“default” used to set a default value for a variable. If the variable is unset or an empty string, then the default would be display. This modifier accepts one parameter which is the default value to show. {$foo|default:’Default text’} Advertisements

Count number of characters in a string in smarty

We can count number of characters in a string through the smarty. Smarty provide a modifier called “count_characters”. {$str|count_characters} Above statement will display the number of characters in the string excluding the white-spaces. {$str|count_characters:true} Above statement will display the number of characters in the string including the white-spaces.

Capture in Smarty

{capture} is used to collect the output of the template between the tags into a variable. All content between {capture name=’test’} and {/capture} would into the variable in specified catpure name. The captured content can be used in the template from the variable {$smarty.capture.test} where “test” is the name of that capture. If we don’t provide the name attribute, then “default” will be used as the…

literal tag in smarty

{literal} tags allow a block of data to be taken literally. This is typically used around Javascript or stylesheet blocks where {curly braces} would interfere with the template delimiter syntax. Anything within {literal}{/literal} tags is not interpreted, but displayed as-is. If you need template tags embedded in a {literal} block, consider using {ldelim}{rdelim} to escape…

Foreach in smarty

Writing a foreach in smarty is very easy. It has very easy syntax, which is given below: {foreach from=$myArray item=i name=foo} {$i|print_r} {/foreach} In the above example “$myArray” is the array which is about to traverse and “$i” is the single row of that array.