Anyone who has ever used a template engine (Smarty, etc) will almost always do so because of the desire to keep a consistent master navigation/layout.
Knowing that, we can assume almost all site which use a template engine will have at least 2 templates:
1) Master template(s)
2) Page template(s)
When an application gets complicated one might even modularize their presentations into three or more layers - sub page templates.
Assuming we are using a MVC architecture (Zend) and we initialize the master template inside the front controller and inject each controllers(view) output into the master template. How would you typically handle arbitrary level of template nesting?
Sample code, comments, disscussion, etc???
Unlimited levels of template nesting...
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I don't usually do anything hierarchical in the template system. Template blocks, which are really just multiple templates in a single file, are as far as I go. For hierarchy For me templates are just for tag replacement.
I use a structure of View or Response objects for hierarchies. They allow me to attach either a string or an object with a render() method to a tag in a template.
I use a structure of View or Response objects for hierarchies. They allow me to attach either a string or an object with a render() method to a tag in a template.
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I should have mentioned in my original message...I have learned to distinguish between two types of templates:
1) Push - A template with holes which are plugged by pushing in content
2) Pull - A template with includes, which are pulled into the template
These techniques are not mutually exclusive, both can be used in a single template.
By this definition, it sounds like your templates are simply static HTML pages with holes, so I assume your using a push system?
1) Push - A template with holes which are plugged by pushing in content
2) Pull - A template with includes, which are pulled into the template
These techniques are not mutually exclusive, both can be used in a single template.
By this definition, it sounds like your templates are simply static HTML pages with holes, so I assume your using a push system?
I'm not sure I totally follow...can you demonstrate with some psuedo-code?I use a structure of View or Response objects for hierarchies. They allow me to attach either a string or an object with a render() method to a tag in a template.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I'm not sure if you guys use a similar method to my own, but...here is a simplified version of how I might use multiple templates:feyd wrote:Sounds like arborint's is pretty similar to mine.
Basically how it works is I have a large tree of renderable objects. Each object understands how it is supposed to be represented via very simple templates each is given that wraps around the information they carry.
Code: Select all
$smarty->assign('title', 'Master template TITLE');
switch($page){
case 'home':
$buff = $smarty->fetch('home.tpl');
break;
case 'about';
$buff = $smarty->fetch('about.tpl');
break;
}
$smarty->assign('page', $buff);
echo $smarty->fetch('master.tpl');Is this essentially the technique you use - ignoring the specifics of a switch above or a front controller, etc...
If you use Zend and it's FC implementation...how do you specifically pass content from a controller buffer to eventually interpolated into the master template inside the FC???