Do we *have* to use Smarty?

zachharkey
zachharkey's picture

Joined: 2005-05-21
Posts: 11
Posted: Tue, 2005-05-31 13:16

Is there any way to do away with the Smarty template engine and just use straight php? For instance in Drupal, they have ditched Smarty and other template engines in favor of phptemplate which is basically pure php.

There are several articles arguing the merits of different template engines.

For instance Brian Massassi argues

Quote:
While Smarty gets it right in that sense [that it does allow] you to harness pretty much every aspect of PHP, there are still some problems. Basically, it just provides an interface to PHP with new syntax. When stated like that, it seems sort of silly. Is it actually more simple to write {foreach --args} than <? foreach --args ?>? If you do think it's simpler, consider this. Is it so much simpler that there is value in including a huge template library to get that separation? Granted, Smarty offers many other great features (caching, for instance), but it seems like the same benefits could be gained without the huge overhead of including the Smarty class libraries.

At the very least, something like this would allow developers already familiar with php to step right into creating gallery templates without having to hit such a productivity speed bump. And for those unfamiliar with php, it would actually familiarize them instead of introduce them to an even more complicated way to work around it.

I'm not trying to start a flame over smarty vs php, just find out if it's possible to do without it, and if anyone sees the possibility of a future without it.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-05-31 14:11

Short answer: No, without changing (an (to me) unknown amount of codelines in) G2, you can't just use pure PHP instead of smarty.

smarty seemed like the best choice 3, 2 years ago when bharat designed the framework of G2. 1-3 months ago, there was a discussion, also started by a forum user, why we chose smarty and if we didn't want to change to another templating engine (forgot the name). The conclusion was, that the other templating engine didn't exist 3 years ago and it actually could be a better choice.

You can find the discussion with the forum search function, limit your search to the G2 forum category.

It's not what you're asking for, but with {php} {/php} you can put arbitrary php code into the smarty .tpl templates.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Wed, 2005-06-08 09:54

I don't think that we can make an incremental change like this. G2 is modular and a single page can be generated with content from many plugins (modules and layouts). It works by letting each plugin do whatever calculations are necessary (retrieve data from the db, etc) and store its data into a central template data structure along with pointers to any templates necessary to render its individual chunk. Then at the end of that process, we do a single pass over the templates and render them all at once, letting each one have a reference to our data structure. This allows modules to interact with each other at the template level, among other things.

We can certainly move to a different templating engine, but it would mean that we'd have to move everything over at once. Doable, but there'd have to be a really good reason to do it.

Right now I'm still pretty happy with Smarty. I prefer its terse template syntax. We do use PHP templates in the installer and upgrader and whenever I work with those templates I'm always irritated by how much I have to type in order to just print out the value of a single variable, eg:

<?php print $foo ?>

vs.

{$foo}

Or with arrays:

<?php print $foo['bar'][0] ?>

vs.

{$foo.bar.0}

That's my personal preference, of course. I complete understand what you're saying about the Smarty learning curve. I still have to refer back to the manual from time to time...

 
fastfingertips

Joined: 2006-02-16
Posts: 1
Posted: Thu, 2006-02-16 12:04

beceause you have some lacks?

You may try also:
<?= $foo ?> (does same thing :P)