Hi folks, I’ve been kicking around this idea, and I’d love your feedback.
For most pages on my site, the same basic overall template is used. What varies form template to template is the main content area, or sometimes a sidebar, where we might have certain TVs in use, tables of data, or what have you. Seems to me that maintaining a separate template file for each instance is a bit of a pain.
My proposal is to have a snippit which returns a chunk based on the current document’s template. So you might have:
[[ifTemplate? &template=`affiliate` &chunk=`affiliate_template`]]
[[ifTemplate? &template=`article` &chunk=`article_template`]]
and so on.
Is there a flaw to this methodology? Caveats? I am planning on basing the ifTemplate code on another snippit I have called chunkIf, which I am using to insert a chunk based on whether a TV is set in the current document.
A question: how do you read the current document’s template, by name?
Revo 2.0.8-pl
-
☆ A M B ☆
- 24,524 Posts
Why not just put the chunk in the template? Or make better use of TVs? How about a TV that offers a list of chunks with radio buttons or check boxes? @INHERIT is also useful. I rarely find it necessary to use more than one template.
Let me expand then: Yes, having different templates for grouping TVs is part of the problem, in that you then have to maintain all these separate template files/code. But I thought that each template’s html code (too bad we have two used for the work templete in ModX) would then just be the same call to a chunk "globalTemplate", and that chunk would dynamically include other chunks based on the current document’s template. Sottwell said "why not jsut put the chink in the template", but that’s what I’m saying, I want only the chink pertaining to the current template to be inserted, while not having to maintain multiple templates.
For instance you have a template that looks like this:
{{siteTemplate}}
and this chunk contains the following:
{{siteHeader}}
{{contentChunk}}
{{siteFooter}}
and then the "contentChunk" is as in my original post above, with dynamically called chunks depending on the current site’s template. Thus, every template is the same chunk call.
Sottwell’s idea to have a TV with a list of chunks and such seems to duplicate teh very idea of a template, and anyway, for large and complex sites, thsre are many reasons why one might want more than one template. THis is the situation I’m describing. Once I get a working snippit I’ll post it for further comment.
Cheers!
Revo 2.0.8-pl
Oh, you just brought up one of my favorite MODx subjects!
I make heavy use of PHx to do exactly what you are saying - create more complex templates that can deliver a wider variety of page views. Specifically, I use IF statements in PHx, primarily based on the way I structure the document tree (parent-child relationships), to achieve this. It is great! Maybe I need to do a blog post about this. It is a kick of mine, to see how far I can get with a single template, but still have a sensible and clean template layout that is manageable.
The only problem I see with having one template for multiple layouts is that all the TVs will be assigned to all the documents.
So when the client edits a page, he sees all the TVs but only some will be displayed on the frontend. Might be confusing
If it’s only one or two TVs, I guess it’s ok.
But when you have to manage 10 TVs with phx, I would suggest using different templates.
@Cipa Check out ManagerManager!