Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty Theory - Should template define required content?

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
TheOddPerson
Smarty n00b


Joined: 19 May 2013
Posts: 3
Location: Canada

PostPosted: Tue Sep 03, 2013 4:08 pm    Post subject: Smarty Theory - Should template define required content? Reply with quote

Hello

I am programmer, I've built a few websites previously but this is my first time using smarty, php, and I haven't used much Javascript before.

I'm using PHP 5.4, Smarty 3, MySQL 5.5 with Apache 2.2 on a Raspberry Pi.

Anyways my question is this --

Should it be left to the template designer what content to display on specific pages or should it be hard coded into the .php file?

ie:
index.php includes:
Quote:

$smarty->display('htmlstart.tpl');
$smarty->display('header.tpl');
$smarty->display('userbuttons.tpl');
$smarty->display('leftmenu.tpl');
$smarty->display('search.tpl');
$smarty->display('content.tpl');
$smarty->display('othercontent.tpl');
$smarty->display('morecontent.tpl');
$smarty->display('map.tpl');
$smarty->display('footer.tpl');
$smarty->display('htmlend.tpl');

..and there could be more..


I guess there could be a bunch of 'ifs' in the php customizing the content, or perhaps I could let the browser request (Get/Post) define which content is displayed..

or should the template be able to call upon each of those 'modules' as it needs. I would like the website to be as dynamic as possible and having each component/module of the website segregated into divs and placed into it's own .tpl file seems like a logical solution but may make the actual presentation code of the website messy.. say when I want to display a list of articles and only display edit/moderation buttons for certain users.

soo I was thinking of rather than having the .php code define what data the presentation code gets and what files it needs to display, I could possibly have the html code request whatever data/modules it needs whenever the template designer thinks it's necessary.

I'm just not certain how I would program that with javascript or perhaps I should be using a different language or method?

I would like to get a handle on the 'theory' and 'best practices' of using Smarty before I'm several hundred lines down the wrong coding path.

Thank you all for your help.
Back to top
View user's profile Send private message
TheOddPerson
Smarty n00b


Joined: 19 May 2013
Posts: 3
Location: Canada

PostPosted: Wed Sep 04, 2013 3:25 pm    Post subject: Reply with quote

*pretends to be someone else*

See Template Inheritance
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4692
Location: Hamburg / Germany

PostPosted: Thu Sep 05, 2013 3:25 pm    Post subject: Reply with quote

To load required php modules and data from the individual templates you could use plugins.

See http://www.smarty.net/docs/en/plugins.tpl
and http://www.smarty.net/docs/en/plugins.functions.tpl
The function plugin could fetch required data and assign it t template variables.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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