Overview
KB
Learn PHP
PHP techniques
PHP Smarty Functions
PHP Web Email
Secure development
PHP Security Scenario
SSH and SFTP
PHP Smarty
PHP Smarty Modifiers
PHP Smarty Caching
PHP Smarty Misc
CakePHP
Zend Framework
PHP basics

PHP Smarty Modifiers

Smarty modifiers allow you apply formatting techniques within a template. This saves you from having to apply the formatting within the PHP code, further separating presentation from code and ensuring a more consistent look. A php smarty modifier is most often applied to variables, but can be applied to literal text or functions as well. To apply a modifier to a variable, follow the variable's name with the pipe (|), then the name of the modifier:
{$var|modifier}
Modifiers can even be chained together:
{$var|modifier1|modifier2}
The modifiers will be applied in order from left to right. If a modifier accepts additional parameters, follow the modifier name with a colon, then the parameter:
{$var|modifier1:parameter}
Smarty supports the ability to use any PHP function as a modifier. You can even create your own modifiers using plugins.

Changing Case

Click for full image of the modifier result
The "capitalize" modifier will capitalize the first letter in a value. The "lower" modifier will make the entire value lowercase; "upper" will make it all uppercase. The image at right shows the result if you change the template in the sample instructions to
Name: {$name|upper} 

Address: {$address|upper}

Concatentation

The "cat" modifier appends a literal string, passed as a parameter, to the value.
{$var|cat:' also print this'}

Article continues:  next page>>

 Download NuSphere PHP IDE

Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.

 Buy NuSphere PhpED® now

Best PHP Editor and complete PHP IDE.
NuSphere PhpED 19.0 is available from our online store front.

 Special Team4 Offer

Get 4 copies of PhpED for the price of 3!

Optimum solution for development teams.
PhpED 19.0 Team4
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward,
Director of Technology
caboodal.com