Hi all,

I've been trying to build a few Drupal sites with the supported phptemplate engine and I can't seem
to get it right.I've used smarty before and I'm wondering why first class support was not provided for
Smarty in the Drupal 6.0+ distro? IMO Smarty is the better templating engine and obviously streamlines
tasks for both designers and developers?I've downloaded the smarty-6-20 engine and I'm still having issues
getting it up.There's something not right about having PHP code in templates, coupled with all those
print '

,lean code and a flexible,extensible template.

Seeing I root for Drupal and I'm simply awed at Drupal's features(I'm migrating to core Joomla sites to Drupal presently), I'm finding it difficult seeing the rationale behind the phptemplate engine.It takes me back to what I was running away from in the first place,
having to generate HTML from PHP code, moreso dynamic HTML from custom views and themes!
I want to suggest making Smarty the default templating engine(hope I don't fired for saying that), as PHP in template code
complicates matters I think.I vote for Smarty to be the default templating engine and ask for better documentation
if possible.I will try and contribute tips and tricks from my experience whenever I can.

Thanks,
Ozzy

Comments

ozioma’s picture

I've been trying to build a few Drupal sites with the supported phptemplate engine and I can't seem
to get it right.I've used smarty before and I'm wondering why first class support was not provided for
Smarty in the Drupal 6.0+ distro? IMO Smarty is the better templating engine and obviously streamlines
tasks for both designers and developersI've downloaded the smarty-6-20 engine and I'm still having issues
getting it up.There's something not right about having PHP code in templates, coupled with all those
print "" etc.... Drives me crazy!Smarty takes the drudgery out of all that.You are left with clean
,lean code and a flexible,extensible template.

Seeing I root for Drupal and I'm simply awed at Drupal's features(I'm migrating two core Joomla sites to Drupal presently), I'm finding it difficult seeing the rationale behind the phptemplate engine.It takes me back to what I was running away from in the first place,
having to generate HTML from PHP code, moreso dynamic HTML from custom views and themes!
I want to suggest making Smarty the default templating engine(hope I don't get fired for saying that), as PHP in template code
complicates matters I think.I vote for Smarty to be the default templating engine and ask for better documentation
if possible.I will try and contribute tips and tricks from my experience whenever I can.

Thanks,
Ozzy

Simplicity+Excellence by Design

styro’s picture

There's something not right about having PHP code in templates

Why not? PHP itself is an HTML templating language :)

It's the kind of coding you do in the templates that matters, not what you write the code in.

--
Anton

ozioma’s picture

Ummmh,well, it depends.
There are countless scenarios that just call for spitting out raw HTML from PHP, I can't
argue against that.Most times though, it makes more sense to separate presentation from data or processing logic.

Smarty templates allow for just that, and in a very versatile way(with plugins and filters).
I've gone through the code for most phptemplate themes I've come across,where you're constructing tables inside
of divs inside of uls in a loop and spitting out element attributes like style="other php code"
when I could have it all in a HTML-like format inside of a Smarty template.

That way I don't confuse retrieving form data, processing it,querying the db and pushing out the results for display.
It keeps things separated and provides for maintainable code.
If the layout of my presentation changes, say I want to expand the container table or div, or add extra rows with
a top or bottom ul containing links, I only have to modify my tpl file and that's it.
My core PHP code remains separate and I can still update my tpl file with more data as needed.

I think the beauty of Smarty is the plugin/filter mechanism coupled with the fact that you can even include PHP code in
your template if you wish.

I think that beats phptemplate. Let me know what you think.
BR,
Ozzy

Simplicity+Excellence by Design

styro’s picture

There are countless scenarios that just call for spitting out raw HTML from PHP, I can't
argue against that.Most times though, it makes more sense to separate presentation from data or processing logic.

Smarty vs PHPTemplate though is orthogonal to separation of presentation from processing. Even if you use PHPTemplate you should still separate the two.

Arguing that a different language is required to separate the two layers is silly. Should MVC frameworks require different languages for models and controllers to make sure they don't get their roles mixed up?

That way I don't confuse retrieving form data, processing it,querying the db and pushing out the results for display.
It keeps things separated and provides for maintainable code.
If the layout of my presentation changes, say I want to expand the container table or div, or add extra rows with
a top or bottom ul containing links, I only have to modify my tpl file and that's it.
My core PHP code remains separate and I can still update my tpl file with more data as needed.

So do you actually get confused about where you should do those things? Do you accidentally put DB queries in your templates?

It almost sounds like you are doing all your custom coding in your theme? Shouldn't you be using modules for the non presentation parts?

The solution to the problem of putting business logic is templates is to simply stop putting business logic in templates.

I think the beauty of Smarty is the plugin/filter mechanism coupled with the fact that you can even include PHP code in
your template if you wish.

So now that you can put PHP in your Smarty templates, you will need the discipline to not misuse it. Aren't we back at square one now?

PHPTemplate isn't going away - it has developed so strongly over the years that it has mostly now displaced all the other competing theme engines to become the preferred option. It wasn't alway like this though - PHPTemplate was originally a separate download like the Smarty template engine is. I'm sure if enough people actually wanted to use the Smarty template engine in Drupal, it would be in much better shape than it is now.

I certainly prefer using PHPTemplate to having to learn yet another templating language that isn't strictly required.

--
Anton

Michelle’s picture

PHPTemplate is the default engine because people like it. Smarty has been available as an alternate for some time and never really caught on. You're welcome to your opinion that Smarty is better, and welcome to use the Smarty engine. But you'll find a lot more support for PHPTemplate because it's a good engine and works well and is very popular.

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.