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….

Advertisements

Entry filed under: Development, PHP, Smarty.

You’ll always be known by your 80’s hairstyle and that bright pink mini-skirt NextGen Smarty… (Smarty V 3.0)

1 Comment Add your own

  • 1. dgdgdg  |  Wednesday 9th April, 2014 at 12:39 pm

    dfgdgdgd

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts


%d bloggers like this: