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

template inheritance

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
leanweb
Smarty Rookie


Joined: 27 Oct 2004
Posts: 24
Location: Newark, DE

PostPosted: Sat Mar 12, 2005 12:10 am    Post subject: template inheritance Reply with quote

sorry if this has been discussed here before, quick search didnt find anything so here it is.

i wonder if this is doable in the present framework of Smary or whether it may be possible in the future. consider this pseudo-template, suppose its in the file base.tpl:

Code:
{page}
  {header}
    ...html/smarty code for the header...
  {/header}
  {main/}
  {sidebar/}
  {footer}
    ...html/smarty code for the footer...
  {/footer}
{/page}


and then consider the second file, in news.tpl:

Code:

{based-on "base.tpl"}
{main}
  {leancms command="get" field="body"}
{/main}
{sidebar}
  ...smarty/html code to show list of other news items...
{/sidebar}


this construct will be very familiar to anyone who's familiar with OOP programming. the first template is, of course, abstract page framework. you'd then "subclass" pages off this base design. base template would hold all the common properties of subclassed templates.

a subclassed template might override some properties of parent template, for instance, when page calls for altered logo or different footer design.

anyhow, it just sounds to me that this method of arranging templates might have some benefits and should not be that tough to implement.

any thoughts?
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Mar 12, 2005 1:12 am    Post subject: Reply with quote

This is essentially the same thing that was briefly discussed concerning "overlays". I don't mean to be dismissive because it is a great idea from an overall perspective but I think it speaks to a different layer than Smarty is currently targetted at. I think you can do things to process that type of structure using Smarty but I don't think Smarty is particularly geared to do that internally.

For example, you can use some sort of multi-layered template processing (perhaps using a different set of tags for the layout layer) such that the layout layer is processed and then have the "detail" layer fed into it for final processing. In other words, your detail templates become "data" for your layout templates. It is conceivable but requires two passes through Smarty (one for each layer).

Another option is to create a software layer (perhaps using objects) that deals with the layout and includes a method of selecting appropriate templates for the context. There are many ideas on how to do this and several threads on the forums that speak to it. This is how I approach the layout layer (and have discussed it to some extent in various threads) and the general idea in my approach is to create the layout as an object graph that represents the document structure. You feed the graph into a generalized main processing template which can decompose the graph.

You can see my response regarding overlays here: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=4780
Back to top
View user's profile Send private message
leanweb
Smarty Rookie


Joined: 27 Oct 2004
Posts: 24
Location: Newark, DE

PostPosted: Sat Mar 12, 2005 2:14 am    Post subject: Reply with quote

thank you for great response, and not dismissive at all!
Back to top
View user's profile Send private message Visit poster's website
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 -> Smarty Development 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