Greetings,

After reading some threads about what is better PHPTemplate or Smarty. I came to a decision that the single advantage of Smarty is that you don't need to often use php tags and templates looks much easier for CSS guy or designer who does't know PHP.

But, why don't to use '<< Here is an original block.tpl.php listing:

  <div class="block block-<?php print $block->module; ?>" id="block-<?php print $block->module; ?>-<?php print $block->delta; ?>">
    <h2 class="title"><?php print $block->subject; ?></h2>
    <div class="content"><?php print $block->content; ?></div>
 </div>

I rewrote it a little and now it looks as follows:

<?php
$output = <<<EOD
  <div class="block block-{$block->module}" id="block-{$block->module}-{$block->delta}">
    <h2 class="title">$block->subject</h2>
    <div class="content">$block->content</div>
  </div>
EOD;
print $output;
?>

Which is much better and now Smarty needed. More then, you can do all logic before $output = <<

Did anybody try this approach ? May be there are any other advantages of Smarty ?

Thanks.

Comments

ardas’s picture

Sorry, another try :) Drupal incorrectly handles EOD feature.

After reading some threads about what is better PHPTemplate or Smarty. I came to a decision that the single advantage of Smarty is that you don't need to often use php tags and templates looks much easier for CSS guy or designer who does't know PHP.

But, why don't to use 'EOD' in PHPTemplate to make it as simple as Smarty template ?
Here is an original block.tpl.php listing:

  <div class="block block-<?php print $block->module; ?>" id="block-<?php print $block->module; ?>-<?php print $block->delta; ?>">
    <h2 class="title"><?php print $block->subject; ?></h2>
    <div class="content"><?php print $block->content; ?></div>
 </div>

I rewrote it a little and now it looks as follows:

<?php
$output = <<<EOD

  <div class="block block-{$block->module}" id="block-{$block->module}-{$block->delta}">
    <h2 class="title">$block->subject</h2>
    <div class="content">$block->content</div>
  </div>

EOD;
print $output;
?>

Which is much better and no Smarty needed. More then, you can do all logic before $output = EOD line and then designer will work only with HTML.

Did anybody try this approach ? May be there are any other advantages of Smarty ?

Thanks.

adrian’s picture

but often you need to call a function from within a template.

ie: form_render()

--
The future is so Bryght, I have to wear shades.

amnon’s picture

It's a cute idea. I'll borrow it :-)

When I started with Drupal, I was very disappointed to find out that it was using straight PHP (as in phpTemplate) instead of some "elegant" template engine like Smarty or Flexy.

Then I found the following article,

http://www.phppatterns.com/docs/design/templates_and_template_engines

which opened my eyes.

I recommend reading it. It's a funny article which sorts of laughts at template engines.

You may want to follow some of the links at the bottom (especially "Comments by voostind") for further info.