Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty implementation

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
harris
Smarty Rookie


Joined: 15 Oct 2003
Posts: 5

PostPosted: Wed Oct 15, 2003 10:53 am    Post subject: Smarty implementation Reply with quote

I`m working on a site that has different categories, example:
- view owner
- edit owner
- delete owner
- insert owner

I tried working with 1 main template file, and from that file I include other files i.e: header, footer, etc.

Example:
====================================
view.tpl:
{include file="header.tpl"}
{include file="menu.tpl"}
{if $owner.id neq null}
INSERT HTML CODE TO VIEW OWNER HERE
{/if}
{include file="footer.tpl"}
====================================

My question is: is this a good implementation of smarty, because I studied some different methods.
I also tried making more than 1 instance of smarty, i.e:

=======================================
$header = new Smarty;
$header->assign("header_data", "blablablabla");
$header->display("header.tpl");

$menu = new Smarty;
$menu->assign("menu_data", "blablabla");
$menu->display("menu.tpl");

$content = new Smarty;
............

etc, etc.
=======================================

I also looked at some "bigger" php/mysql/smarty projects, for example PHPBB, Xoops, and I noticed that some projects use only a few or only 1 tpl file, and i.e. PHPBB uses a lot of tpl files.

Is there any noticable speed difference between this 2 different methods, and what method is "the more official way". And of course.. if anyone has a better way... I`m interested! Razz

Regards,
Harris
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Oct 15, 2003 2:02 pm    Post subject: Reply with quote

In my experience, calling $smarty->display() once to render the entire page works well. The templates can sort out what other templates need to be included to make up the page. You can assign data to aid in how they go together too. This keeps your application logic clean and puts the responsibility of template heirarchy management in the templates. If at all possible, don't make the application logic rely on how the template files are organized. ie. if you wanted to completely change the interface one day and reorganize the templates, the application logic shouldn't need adjusting.

One method I use is an initialization template:

$smarty->display('init.tpl');

The init.tpl is the only template the application ever calls directly. This init.tpl does global initialization stuff (like loading configs from an init.conf) then uses assigned data to figure out where to go from there: typically choosing between something like layout.tpl or printable.tpl.
Back to top
View user's profile Send private message Visit poster's website
harris
Smarty Rookie


Joined: 15 Oct 2003
Posts: 5

PostPosted: Wed Oct 15, 2003 2:26 pm    Post subject: Reply with quote

Okay, so in you're opinion the best way is something like this

site.tpl
====================================
Code:

{include file="header.tpl"}
{include file="menu.tpl"}

{if $my.cat eq 1}
{include file="categories/1.tpl"}
{else if $my.cat eq 2}
{include file="categories/2.tpl"}
{/if}

{include file="footer.tpl"}

====================================

An other advantage of this way is that you don't have to assign global data more than once Exclamation
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP