Mon 24 Jul 2006
Smarty variable modifiers
Posted by dkaz under Programming, PHP
I’m playing around with a PHP framework that uses Smarty Templating Engine to separate logic from its presentation, and I’m very impressed thus far.
Smarty seems to pull off elegant API, powerful features and oustanding performance - a rare triumvirate.
On top of that, it has a vibrant community and a ton of documentation scattered around the web. I’m liking this PHP thing more than I like to admit.
Check out how Smarty pulls off variable modifiers (one of my favorite features) with shell-like pipe syntax:
{* 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”}

July 25th, 2006 at 8:43 am
I dont think Smarty is smart solution for the so-called “separation business logic from presentation”. What they try to do is to separate PHP code from HTML code only by inventing a new templating language. So Smarty is poor solution that was invented for poor PHP3 developer.
Use Savant instead: Savant