Do either of these Smarty-based theme engine work properly for Drupal currently?

Smarty Theme Engine:
http://drupal.org/project/smarty

wgSmarty:
http://drupal.org/node/26897

The Smarty Theme Engine page says it's "recently updated" but the page itself hasn't been updated since December 2, 2004 ...

On the wgSmarty page, it says: "wgSmarty is much more closely integrated with Drupal than the existing smarty theme engine". How is this so?

Also, it says that "wgSmarty is currently experimental and is only available in CVS". Is this still the case? I see Version 4.6.001 of wgSmarty for download. Is this still considered a pre-release version? Meaning it's not usable or recommended for production sites?

Comments

adlitinc’s picture

The phptemplate will be the default theme engine for the upcoming 4.7 release and it is also available for drupal 4.6.

Many template are available for the phptemplate engine.

Do you have a specific requirement for smarty?

greygoo’s picture

I'm familiar with and really like smarty-based theme engines, much like PostNuke's Xanthia theme engine. My requirement would be a theme engine that completely separates php from html code, where template files have only html code with only smarty tags used to place php content within the template.

http://www.spaz.org - Semi-Permanent Autonomous Zone

greygoo’s picture

Just to clarify, I've never used the phptemplate engine. But I assume that it will require touching of PHP code. What I'm looking for is a theme engine where the designer won't have to look at any php code, but still have full control of the design through using just css and html. I know smarty-based theme engines allow for this. If phptemplate can also work in the same way, I'd like to know as well.

http://www.spaz.org - Semi-Permanent Autonomous Zone

adlitinc’s picture

I'm working on a new phptemplate and it seems pretty straightforward. Mind you:

"Smarty theme engine is a theme engine maintained by Travis Cline designed to easily use the Smarty Template Engine syntax in drupal themes. It is largely ported from the PHPTemplate theme engine."

for reference, take a look at the handbook for the theme engines:

http://drupal.org/node/509

and look at some of the downloadable themes from either engine to see what you like but phptemplate seems to be the favorite

greygoo’s picture

Are you having to touch php code when working on phptemplate?

http://www.spaz.org - Semi-Permanent Autonomous Zone

sepeck’s picture

It depends. You can use the page.tpl.php from an existing theme link argaabee or friends electric, both tableless designs, or write your own. It's not really hard and fairly straight forward. This is the page.tpl.php I use on my site (http://www.blkmtn.org/node/232) and it outputs tableless css.

So, if you just grab the base stuff from an existing theme, and have the designer do all the css, then no, you don't have to touch css at all.

-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

tclineks’s picture

Though I may be biased....

as I maintain the (non-wg)Smarty Theme Engine.

I suppose it has been long enough to remove the "recently updated"...

I think the non-wg Smarty is much superior and think his much more closely integrated claim is dubious since I made updates when I took over.

I've offered quick support and have been using it for every drupal project I've worked on, ever.

There is some somewhat-undocumented flexibility with the per-theme, user-defined register_functions function which removes virtually all need for {php} tags. This function name is being removed to favor 'smarty_register_functions' instead.

Quick example:

in per-theme smartytemplate.php:

// this registers our functions with the engine so they are accessible within our tpl files
// this function will be expected to be named 'smarty_register_functions' in the future
function register_functions() {
  return array('assign_is_admin' => 'do_smarty_assign');
}
function do_assign_is_admin($params, &$smarty) {
  global $user;
  $var_name = isset($params['var_name']) ? $params['var_name'] : 'is_admin';
  $smarty->assign($var_name, $user->uid == 1);	
}

in a template (.tpl) :

...
{assign_is_admin}
{if $is_admin}<p>Hello Admin!</p>{/if}
{* and to make the example more interesting: *}
{assign_is_admin var_name='superuser'}
{if $superuser neq true}
  {* call an imaginary function that returns output directly *}
  {run_imaginary_function_for_nonadmin param1=$value2 param2=4 param3='pineapple'}
{/if}
<p>Lowly .</p>
..

Recent more advanced implementation description

I implemented a previous/next navigation among peers at the current menu level in a very elegant and flexible manner if I don't say so myself. It ends up assigning a previous and a next variable (prefix supported) to smarty (as an array or false if the link doesn't exist) and I check whether to show a greyed link or the active link. I even have the node title (i.e. $previous.title) in there for an anchor title="" attribute or alt-text on an image).

Smarty Variables

Also, currently assigned Smarty values are available in the smartytemplate.php functions as $smarty->vars['var_name'] (use func_get_arg(1)) where {$var_name} would be available within the template scope.

One caveat is to access currently assigned variables within a {php} block in a template file you must use $this.vars['var_name']

The Code

I also am more closely in line with the coding conventions (1 class naming error I'm choosing to ignore see http://drupal.org/files/projects/smarty.status vs http://drupal.org/files/projects/wgsmarty.status ), do permission checks and alert the user before rendering site unusable by activating a Smarty theme without proper directory permissions on the templates_c directory. It's a more direct port of phptemplate so future changes will be easier to merge and maintain and themes will be (and are!) very easy to move over.

I did choose not to support some extraneous options. Though it doesn't support Smarty caching (it would be an easy addition but I doubt there's much desire for it -- we have a layer of caching already).

Reading the open issues for wgSmarty -> http://drupal.org/project/issues/wgsmarty shows that a custom per-theme .php file isn't currently supported which is a great detriment.

Themes

I offer to convert any existing phptemplate theme if requested. It's a very easy process.
The code is much cleaner and you lose virtually nothing in terms of speed (a few cycles).

The cleanliness of the code and manageability thereon out is wonderful especially if you have a designer that isn't php-keen.

Statistics

2266 downloads for Smarty Theme Engine vs 567 for wgSmarty Theme Engine and two bugs arose for wgSmarty in that time.

Drawback

There is one issue in that I chose not to implement individual primary and secondary links as I saw it as a kludge (as it is template-engine-wide in 4.6.x).

I'll update for 4.7 which supports this natively and if I get enough requests for a backport (won't really be much of a backport afaik) I'll do so.

Whew.

I think there are other advantages, feel free to bring up any issues.

Sorry if that came out rantish, I tried to provide some sort of though organization..

Travis

fireater’s picture

You got me convinced Travis.
Thanks for taking the time to put up your case.

I might be the only one who has explicitly said the above, but your long post might have prompted many to take another hard and long look at your project before deciding.

Cheers.

nicopepe’s picture

I have two questions for you.
- 1 - Is the compilation of smarty template make speed improvement comparing with phptemplate ?
- 2 - You seem to have developped a script to convert phptemplate to smarty template. Is this script available to all ?

Thank you in advance for your reply

tclineks’s picture

There is an infintesimally small slowdown with Smarty but it's teeny.

Excerpt from the Smarty 'Why Use Q/A':

Q: Template take time to parse, making applications much slower.

A: That may be true in some cases, but with Smarty it is no slower than executing a PHP script. On the first execution of a template, Smarty converts the template files into PHP scripts (called template compiling.)

My phptemplate-to-smarty theme converstion script is a hacked together set of regex rules not worth publishing.

It's just a time saver for the grunt work -- though the time i spent writing it hasn't made up in conversion time for me =/ -- yet.

If I clean it up I may release it -- I can send you a copy in its current state if you contact me through my form (and share your conversion).

lvthunder’s picture

Any idea when a version for 4.7 be available. I would like to use the smarty engine in a site I want to develop and I want to use 4.7 for the site since it is a brand new site. No need starting with 4.6 since 4.7 will be out before I finish the site.

tclineks’s picture

I've written much of the code -- should have it out this evening if I have time to clean it up and do finishing.

tclineks’s picture

The DRUPAL-4-7 tag isn't yet enabled for theme-engines so it's not being automatically packaged.

http://drupal.org/files/projects/smarty-cvs.tar.gz
will work with 4.7

tclineks’s picture

Tag is now recognized (has been for a bit now).

stratosgear’s picture

Hey,

My experience tells me that if you want to access a currently assigned variable within a {php} block in a template file then you have to use: $this->vars['node']->variableName instead of $this->$this.vars['var_name'] that you are mentioning in your comment.

I'm using 4.6.5, BTW (don't know if that matters...)

Stratos

tclineks’s picture

Whoops.

You're right -- sort of =)

More generally it's $this->vars['var_name']

As node is an assigned variable.