To use SMARTY?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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:
User avatar
JMichaels22
Forum Newbie
Posts: 5
Joined: Mon Feb 13, 2006 10:14 am
Location: Chicago Burbs, IL

Thanks!

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Ugh.. conditionals in a template file.. I knew it :x

:wink:
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
Post Reply