Learn PHP
PHP techniques
PHP Smarty Functions
PHP Web Email
Secure development
PHP Security Scenario
PHP Smarty
PHP Smarty Modifiers
PHP Smarty Caching
PHP Smarty Misc
Zend Framework
PHP basics

PHP Smarty Modifiers


The "count_characters" modifiers prints the number of non-whitespace characters in a value. If passed a parameter of true, it will count all characters, including whitespace. The "count_paragraphs" modifier prints the number of paragraphs in a value. The "count_sentences" modifier prints the number of sentences in a value. The "count_words" modifier prints the number of words in a value.
Click for full image of the formatted date

Formatting Dates with Smarty Date Modifier

The "date_format" modifier can be applied to timestamps to format a date:
The formatting parameters are the same as those in PHP's strftime() function. Without providing the formatting parameters, the date will be formatted as Mon D, YYYY (the short version of the month, the day as one or two numbers, and the year in four digits). The current timestamp can be represented using the special $smarty variable: {$smarty.now}. To insert the current date in the default format, you would place this in your template (see the image at right):

Assigning Default Values

You can provide a default value for a variable by using the "default" modifier:
{$var|default:'some value'}
If a value is provided for $placeholder, it will be used, otherwise the default will be used in the generated page. With PHP's error reporting set to E_ALL or E_STRICT, this will create an "undefined variable" error. The solution is to either adjust the level of error reporting in the script or to use a more formal IF-ELSE conditional:
{if $var eq ''} 

   some value 



A default value can be provided for a variable for the whole template by using the assign function:
{assign var='var_name' value=$var_name|default:'some value'}
This line would be needed prior to any reference to $var_name in the template.

Article continues:  <<previous page  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