Page 2 of 2

Posted: Fri Feb 17, 2006 7:01 am
by Jenk
Oh, so it's the pedantics game :P

Well in that case, it can all be condensed further by the logic into:

Code: Select all

?>

<div class="tableContainer">
<?php

if ($content->hasRows('tbl_MachineInfo')) {
    $content->getHTMLTable('tbl_MachineInfo');
} else {
    print 'No data';
}

?>
</div>
Anyway.. this is turning into a fanboy argument. I've already said I use Smarty quite often, I just think it's daft to create a whole new syntax, for several reasons, when PHP can be used itself and more importantly, PHP is of a recognised syntax, or should I say, shares the most common syntax style.

Posted: Fri Feb 17, 2006 7:16 am
by neophyte
I've used Smarty and I've used straight PHP. I'd use templates if my client had "designers" who wanted access to the templates. The argument that PHP could cause errors is a good one. If I know I'm the only one likely to touch them, I just use straight PHP. As far as separation goes, all that is required (with or without templating engine like smarty) is good disciplined programming. :wink:

Thanks!

Posted: Fri Feb 17, 2006 7:39 am
by JMichaels22
Thanks to everyone with all of your replies and examples, it has been very helpful!

Looks like I will just concentrate on the PHP language itself and then learn SMARTY later on.

Thanks again for all your replies!!!

-Jassen

Posted: Fri Feb 17, 2006 8:00 am
by John Cartwright
Ugh.. conditionals in a template file.. I knew it :x

:wink:

Posted: Fri Feb 17, 2006 8:14 am
by Jenk
I'm not a fan of conditionals in a template either, but when it comes to the crunch.. it's hard to avoid them.

If the design of the site itself requires a condition, such as the example I posted of showing a table if it has data, if it doesn't then show a message stating so, then a condition pretty much has to be in the template :)


The absolute ideal (imo..) would be something like:

Code: Select all

?>

<?xml DOCTYPE blah.. ?>
<html>
  <head>
    <title><?php $page->getTitle(); ?></title>
    <link rel="stylesheet" href="<?php $user->getStyleSheet(); ?>" type="text/css" />
  </head>
  <body>
    <div class="page">
      <div class="bannerMenu">
        <?php $page->getBannerMenu(); ?>
      </div>
      <div class="tbl_News">
        <?php $page->getHMTLTable('tbl_News'); /* this will contain the condition and will echo the table 
                                                                         or the no data message as a result */ ?>
      </div>
    </div>
  </body>
</html>
Where the <?php ?> segments are as close to just place-holders as possible.

But the problem faced there, is what if the design changes and the site owner now wants an image displayed instead of a message, or even just the message itself to change? The designer has a look - and can probably make the change, but is not supposed to - sees it is a logic process, so now the logic developer has to get involved.