Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Template nesting

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


Joined: 11 Oct 2009
Posts: 1

PostPosted: Sun Oct 11, 2009 10:59 pm    Post subject: Template nesting Reply with quote

Hi,

I'm not sure how to call this so I hope "Template nesting" describes my problem sufficiently.

I am trying to develop a website/forum system in which I am using Smarty. I used Smarty 2 for a long time, but now I've decided to try Smarty 3, just to see how it works and if it would require much different coding.

Currently, I model all kinds of objects that are on the website (menus, forums, threads, posts, banners, footers etc.) as 'Template objects', each having their own tpl template file in which the html and tags are put that shape that specific object.

I then use 'container tags' in the templates that mark positions where Template Objects (and thus the parsed template code) should be included.

Example:

menu.tpl
Code:
<div class="menu">
//menu html and tags in here...
</div>


main.tpl
Code:
<div class="left">
{^left}
</div>


And then in PHP I do this:

// [ Smarty setup here ... ]
$main = new Main();
$menu = new Menu();
$main->addChildTemplate("left", $menu);

I use a prefilter to change the {^left} container tag into code that is similar to what the {include} tag produces, but slightly changed so that it includes the template(s) belonging to whatever objects are assigned to the node when calling addChildTemplate().

Result:
Code:
<div class="left">
<div class="menu">
//menu html and tags in here...
</div>
</div>





So basically what I want is a way to mark spots (the 'container tags') inside template files where sub- or childtemplates can be included, similarly to the include tag, but of course variable so that the PHP code actually decides which template gets included rather than a fixed parameter value like the include tag has.

1) It has to allow multiple templates in one node.
2) Each node's attached templates should be different per instance of template, so if I create two menu objects in the example above, and attach one to the left node of the other, it shouldn't go into an infinite loop.


My question is, what is the best way to code this, using Smarty 3?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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