Smarty & Nested IF’s
Sunday 20th May, 2007 at 2:04 pm 1 comment
Smarty is a great templating system for PHP – however if you’ve ever tried to do complex or reusable templates you can quickly find yourself with lots of nested IF’s.
They can be a pain to debug and trace through – especially with an abstracted template environment (such as Smarty) – as it’s impossible to step through the template generation line by line.
A solution to writing cleaner code is to use something like:
switch ($var) {case "fred":break;case "wilma":break;default:break;}
Unfortunately Smarty doesn’t have such syntax – but Smarty has a superb plugin environment that allows customisation of every aspect of templates. The main maintainers of Smarty pointed me to an example, that with a little adjusting, allowed the switch/case statement to be implement.
The details of the plugin can be found on the Smarty Forums here.
Happy templating….
Entry filed under: Development, PHP, Smarty.
1.
dgdgdg | Wednesday 9th April, 2014 at 12:39 pm
dfgdgdgd