Smarty

All style (template, theme and imageset) related questions for the new release; advice, feedback here please.
User avatar
Dabroz
Registered User
Posts: 19
Joined: Mon Mar 01, 2004 1:45 pm
Location: Poland
Contact:

Smarty

Post by Dabroz »

Why shouldn't you use Smarty Template Engine in phpBB2.2???
Dabroz
It worked yesterday...

User avatar
psoTFX
Registered User
Posts: 1984
Joined: Tue Jul 03, 2001 8:50 pm
Contact:

Re: Smarty

Post by psoTFX »

Because it's huge and unwieldly and unecessary for what we need. We do however use bits of Smarty for conditional "logic".

User avatar
Dabroz
Registered User
Posts: 19
Joined: Mon Mar 01, 2004 1:45 pm
Location: Poland
Contact:

Re: Smarty

Post by Dabroz »

Yeah, that's partly true, Smarty makes some huge parts of code for simple tasks, but, however, it has good performance.
Dabroz
It worked yesterday...

sparkster
Registered User
Posts: 182
Joined: Mon Jan 05, 2004 1:18 am

Re: Smarty

Post by sparkster »

phpBB currently (read: 2.0.x) has a fairly good templating system in my opinion that is probably about one-twentieth the size of Smarty. 2.2 has an even better template system and it's still a fraction of the size. Certainly quicker. Smarty is like a whole other language, stupid when all a template variable in Smarty signifies is a glorified version of

Code: Select all

Output template variable: <?php echo( $var_name; ); ?>

User avatar
kuato
Registered User
Posts: 41
Joined: Fri Feb 13, 2004 11:00 pm
Contact:

Re: Smarty

Post by kuato »

I'm not a fan of Smarty either. You have to learn a whole new language just to use it, in fact if you go that far you may as well just use PHP itself for the template engine like Harry Fuechs did with his 20ish line AwesomeTemplateEngine class at http://www.sitepoint.com/forums/showthr ... hlight=css" target="_blank

Smarty puts the onus of looping on the template instead of the logic which drives it. Compare these two template files using smarty and phpbb:

Smarty:

Code: Select all

<table>
  <tr>
    <td>Title</td>
    <td>Text</td>
  </tr>
  {section name="i" loop=$articles}
  <tr>
    <td>{$articles[i].art_title}</td>
    <td>{$articles[i].art_text}</td>
  </tr>
  {/section}
</table>
PHPBB 2.0/2.2

Code: Select all

<table>
  <tr>
    <td>Title</td>
    <td>Text</td>
  </tr>
  <!-- BEGIN articles_row -->
  <tr>
    <td>{articles_row.ART_TITLE}</td>
    <td>{articles_row.ART_TEXT}</td>
  </tr>
  <!-- END articles_row -->
</table>
Using the phplib/phpbb way you as the code designer are responsible for looping and calling assign_block_vars for each row like this:

Code: Select all

$row = sql_fetchrowset($sql);
for( $i = 0; $i < count($row); $i++ )
{
    $template->assign_block_vars('articles_row', array(
        'ART_TITLE' => $row[$i]['art_title'],
        'ART_TEXT'  => $row[$i]['art_text']
    ));
}
Compared to Smarty which encourages the designer to be lazy:

Code: Select all

$row = $db->getAll($sql, DB_FETCHMODE_ASSOC); // using the PEAR DB class
$smarty->assign('articles', $row);
Wow that was easy but now all the logic of looping is done in the template and you have to learn a whole new language to use it. Ugh!

'
Paul Schmidt - aka kuato
My home | My portal for phpbb2.2

User avatar
Dabroz
Registered User
Posts: 19
Joined: Mon Mar 01, 2004 1:45 pm
Location: Poland
Contact:

Re: Smarty

Post by Dabroz »

I don't know how's that in 2.2 but in 2.0.6 there were too many things hardcoded... Also, phpBB's templating system is also kind of language...
Dabroz
It worked yesterday...

sparkster
Registered User
Posts: 182
Joined: Mon Jan 05, 2004 1:18 am

Re: Smarty

Post by sparkster »

If you don't like it don't use it. phpBB's template system is far superior to Smarty in regards to the developers needs and the general needs of the community at large. Theme creators don't always want to go learning a new templating language, but phpBB makes it really easy with simple HTML comment-style tags go start and end loops rather than, as kuato said, writing the whole logic tino a template file.

Also, in regard to Harry's template system - thumbs up. Have you seen his blog over at SitePoint? Pretty good.

User avatar
Ptirhiik_
Registered User
Posts: 526
Joined: Tue Nov 18, 2003 8:35 am

Re: Smarty

Post by Ptirhiik_ »

Dabroz wrote:(../..)in 2.0.6 there were too many things hardcoded(../..)
Are you sure you aren't mixing subSilver template coming with 2.0.6 and the templating system itself ? :)

User avatar
Dabroz
Registered User
Posts: 19
Joined: Mon Mar 01, 2004 1:45 pm
Location: Poland
Contact:

Re: Smarty

Post by Dabroz »

Is it a difference if there's hardcoded things in templating system or theme itself? 2.2 better is this way, :)
Dabroz
It worked yesterday...

User avatar
kuato
Registered User
Posts: 41
Joined: Fri Feb 13, 2004 11:00 pm
Contact:

Re: Smarty

Post by kuato »

Dabroz wrote:I don't know how's that in 2.2 but in 2.0.6 there were too many things hardcoded... Also, phpBB's templating system is also kind of language...
phpbb's templating system consists of very simple HTML tags and some routines for filling in the tags. Pretty much all you need to know are:

Code: Select all

{tag}
<!-- BEGIN block -->
     {block.tag}
<!-- END end block -->
and then two functions you use the majority of the time to fill in the data in your php code:
assign_vars -- for simple tags like {tag}
assign_block_vars -- for loops like the block loop

There are a couple more obscure functions but those two above are what you use most of the time.

That's pretty much 99% of what you use in phpbb templates. The looping and decision making is done at the application level not in the template whereas in Smarty it's the complete opposite.

To see what I mean that Smarty is a whole new language you only need to look at their documentation at http://smarty.php.net/manual/en/" target="_blank Look at all those functions, variables and conditionals! Sure some of it is familiar like if/else, foreach but a lot of it is not. Smarty template files can get really ugly fast.

Ok, enough of me ragging on Smarty :) I actually do use it for simple stuff that's not related to phpbb but you didn't hear me say that <hides> :)
Paul Schmidt - aka kuato
My home | My portal for phpbb2.2

Post Reply