Several slightly varied templates

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
NateTG
New Member
New Member
Posts: 4
Joined: Wed Dec 03, 2008 8:50 pm

Several slightly varied templates

Post by NateTG »

I am using CMSMS 1.5.

I have several templates that are very similar, except for some additional elements near the {content} block.

I had thought to take the top half of the template and make a GCB called 'header' and take the bottom half and make a GCB called 'footer' then sandwich the content block, along with the slight variations, between 'header' and 'footer'.  I read that this is the way to do it.

However, when I make the header global content block, my , , , etc. tags, and doctype are all stripped.  Do I still have to put that on each template?

I searched the forum and couldn't find any information on this, which is surprising because I am sure someone must have run into this before.  Perhaps I am searching for the wrong words.

Is there any better way to 'nest' templates, or create a fake inheritance?  If I could run the output of one template through the {content} of a second template, that would also work well.

Thanks,
Nate
NateTG
New Member
New Member
Posts: 4
Joined: Wed Dec 03, 2008 8:50 pm

Re: Several slightly varied templates

Post by NateTG »

I hacked something out that's working for me.  I didn't really like the GCB method, so I tried using something along these lines:

'parent template'

Code: Select all

<__html>
<head><meta><title> etc. etc.</head>

..lots of happy HTML....
{$childcontent}

</__html>
'child template'

Code: Select all

{capture assign='childcontent'}
..Additional div's, section navigation, etc...
{content}
..more stuff... possible alternate content blocks
{/capture}
{include file='template:parent template'}
This required some modification of the cmsms core, which is not preferrable, but is working for me at the moment. :-\

1. Create a  LoadTemplateByName function (otherwise you have to include templates using file='template:26' or something similar.

2. Insert logic into template_get_template function to utilize LoadTemplateByName if $tpl_name is non-numeric.

3. Change template_get_template function to use $tpl_name instead of ($pageinfo->template_id).  This was causing a problem for me before I created a function LoadTemplateByName, because every smarty template fetch would fetch the page's template, instead of the one specified in the {include} file argument, and causing infinite recursion.  I'm not completely sure why $pageinfo->template_id was used, perhaps there is a good reason?  The same thing is done several times throughout content.functions.php

This allows me to use the method outlined above, through multiple levels of 'inheritance' or 'nesting'.  The site I was using had many templates that were varied only a little.  So I was able to create them with a few lines and then include the base template.

However, I ran into a few issues:

- Changes to parent templates do not propagate to child templates if they are cached
- The {capture} tag is necessary, in preview mode, the {content} assign parameter doesn't seem to work?
- {content} doesn't work in preview mode if it is in the parent template; it must be in the child template

I'm interested to hear any thoughts on whether this is a viable method?  It seems to be working very nicely for me.

I'm happy to help anyone else perform these edits if there is interest.

Nate
Zoorlat

Re: Several slightly varied templates

Post by Zoorlat »

Hi Nate,

Interesting, but I don't quite see what the befefits of this are.  :-\ What exactly are the additional elements near the {content} block you need the nested template for? Depending on what it is, you might be able to achieve somthing similar by just using some smarty logic (together with a custom content blocks) (would be great if cusom content blocks came in a boolean "box" version).

See Calguy's blog for some good tips on smart CMSMS-template making with smarty. (calguy1000.com)

But since I do not understand, I suppose you have already thought of this :)
//Z
NateTG
New Member
New Member
Posts: 4
Joined: Wed Dec 03, 2008 8:50 pm

Re: Several slightly varied templates

Post by NateTG »

Hey Zoorlat,

Yes, something similar could be accomplished using GCB.  I had tried that originally, but it strips out the doctype, head tags, meta tags, title tags, etc., so those would need to still be put on each template.  I know it's not that much, but it's still a few extra lines each template. In my case, the site has several sections, and while each section has the same header & footer, some are two column layout, and some of the two column layout have an additional navigation bar at the top.  Using this method, I was able to create a base template with the header and footer, then a child template that was two columns, and a child template of that one that had the additional navigation.  Now if I change anything on my two column template, all the sections that use it, as well as the ones with the extra navigation, will reflect those changes.

I guess it's more a matter of preference.  This seems more logical to me, and allows me to make a template that contains all the encompassing HTML, instead of breaking it up into a 'header' GCB and a 'footer' GCB, and sticks more to the DRY principle.

Also, GCBs are under the 'content' menu, which implies to me that they are more for content gets used a lot.  This method on the other hand, keeps all the templating stuff under 'templates'.
Zoorlat wrote:(would be great if cusom content blocks came in a boolean "box" version).
I'm interested in your "boolean box version" GCBs.  What do you mean by that?

Peace,
Nate
Zoorlat

Re: Several slightly varied templates

Post by Zoorlat »

Nate,

I am not referring to GCB, but to custom content blocks. A custom content block functions the same way as {content}, meaning you can have multiple {content}-holders in each template. This way you can get multiple edit areas for one template. You can use this to pass on variables (smarty) and have your template put out different codes (menus etc) depending on the value of the variables.

(use {content block='another_content_area'} to add another editable area to the template).

Dunno if this helps, but sounds like you already have a working solution  :).

Cheers!
NateTG
New Member
New Member
Posts: 4
Joined: Wed Dec 03, 2008 8:50 pm

Re: Several slightly varied templates

Post by NateTG »

Sorry to bump this up again,

I have a similar situation with another site I'm doing.  In this case,  I have two templates that will be identical except that one will have two 'custom' content blocks, and the other will have only the default content block.

I don't want to copy and paste another template, because I may need a few of these, and I don't want to apply template changes in three places.

My solution I described above would work, by making a 'parent' template and several child templates with the various custom content blocks, but I'm hesitant to make changes to the code because it makes it hard to upgrade. 

Can anyone suggest a workable solution?

Thanks,
Nate
Post Reply

Return to “Layout and Design (CSS & HTML)”