I Miss Smarty

The last couple of days I’ve been getting my hands dirty with the codebase of one of the projects at work. At first I was kind of excited because it’s always a good experience becoming familiar with the unfamiliar. But imagine how my heart sank when I opened that first .php file and saw code like the following:

<table>
<?php foreach($tableData as $dataRow) { ?>
   <tr>
   <?php foreach($dataRow as $data) { ?>
      <td><?php echo $data; ?></td>
   <?php } ?>
   </tr>
<?php } ?>
</table>

Yes that’s right. PHP code mixed with the HTML markup. It’s a far cry from the neatly formatted Smarty templates that I’ve been working with the past 2-3 months.

There are three places where I usually see this kind of ‘unfortunate’ code:

  1. PHP for dummies books
  2. Templating systems
  3. Ajax payloads from the server

A free cookie to the first reader to guess correctly which category The Project falls in.

Although there’s a good reason why much the codebase is written like the above, that justification doesn’t make working with it any easier. Case in point: I spent the better part of this afternoon pulling my hair out trying to figure out why a block of HTML wasn’t showing up and it was all because I misplaced a </div> insde a triple nested <foreach> structure.

Not the best way to spend your afternoon. Especially during the first week of a new job…

Comments

One Response to “I Miss Smarty”

  1. What’s Smarty? : mnavasca.ca on August 20th, 2009 9:21 pm

    [...] Six months later… and I don’t miss Smarty at all. I’m perfectly happy with Zend Framework’s view scripts and PHP’s alternate syntax tags. Accepting view scripts was easy enough, it’s part of the framework so I might as well use it. However I still couldn’t accept seeing PHP code in my HTML templates: [...]

Leave a Reply