Multiple templated sections in single page

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
ooopie
Forum Members
Forum Members
Posts: 10
Joined: Mon Dec 19, 2011 7:19 pm

Multiple templated sections in single page

Post by ooopie »

I'm building a site where I would like to break the content up into separate "sections". Multiple "sections" may displayed on a single page.

However, I would like there to be a handful of different "section" templates to use, for example:

Section template 1: blue box on left with text, large image on right.

Section template 2: heading, full width paragraph of large text, 3 columns of small text.

Section template 3: three colored boxes each with its own heading, and small text


So a single page of the site might display this, each with different content:

Section3
Section2
Section3
Section1
Section2
Section1
...

Ideally, the site editors could edit each "section" as if it were its own page, with input fields appropriate to the number of text boxes in the section.

Any suggestions on the best way is to set this up?

I suspect there might be a way using a parent page template which displays all of its children pages within itself as "sections". Children pages could each be assigned one of these "section templates"

Is this the best way, and how can I get a page to display its children within itself after the child's content has been processed through the child's template?
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: Multiple templated sections in single page

Post by scooper »

I'd reach for CalGuys CGSimpleSmarty module first.

CGSimpleSmarty has a couple of functions that would be useful to you;

Code: Select all

cgsimple::get_children([$alias][,$showinactive])
Return an array containing information about a pages children (if any)
Arguments: 
and

Code: Select all

cgsimple::get_page_content($alias[,$block])
Returns the text of a specific content block of another page.
So in the template for your top level parent page you could call get_children into an array and then loop through that using get_page_contents for each child.
Just cutting and pasting from the CGSimpleSmarty help something like:

Code: Select all

{$children=cgsimple::get_children()}
{if count($children)}
   {foreach from=$children item='child'}
     {$foo=cgsimple::get_page_content($child.alias)}{eval var=$foo}
   {/foreach}
{/if}
(not tried that code but something like that should work).

Quite how efficient this would be I'm not sure - you would definitely want to make the child pages cacheable if possible, but hopefully it would be ok.
ooopie
Forum Members
Forum Members
Posts: 10
Joined: Mon Dec 19, 2011 7:19 pm

Re: Multiple templated sections in single page

Post by ooopie »

Yes - thank you for the reply.

CGSimpleSmarty can get me close, but as far as I can tell, it only returns the raw content from a page - not the output of a page after processing through the page template, which is what I'm looking to do.
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: Multiple templated sections in single page

Post by scooper »

You're dead right - I should read the question properly.

In which case... I can't really think of an easy way to do it.

You could use a UDT to grab the template for each child then process that template separately. There's some code that might be handy in this thread

Can't help thinking that this is going to get complicated, especially if you have multiple content blocks for a template, but could be done.

Somebody else might have a better idea though ... feels like we should be able to do it.
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: Multiple templated sections in single page

Post by PinkElephant »

I may be misreading but wouldn't using multiple content blocks in the main page template give you what you wanted?

Code: Select all

{content}

<div class="blue-box">
<h2>{content block name='blue-box-text'}</h2>
<img src="{content_image block name='blue-box-image' label='Blue box Image'}" alt="blue image">
...
{content block='heading-fulltext' oneline=true label='Full-width prominent heading'}
{content block='heading-col-01'}
{content block='heading-col-02'}
{content block='heading-col-03'}
...
</div>
(As well as content_image, it's well worth looking at the super-handy CGContentUtils module to set block input types).

Or, if different editors need different permissions for various sections, you could split the blocks across separate pages (where permissions are set) and draw the content into the main template via page_attr:

Code: Select all

{$blue_box_text="{page_attr page='blue-box' key='blue_box_text'}"|trim}
... which pulls in the 'blue_box_text' block from the 'blue-box' page.
ooopie
Forum Members
Forum Members
Posts: 10
Joined: Mon Dec 19, 2011 7:19 pm

Re: Multiple templated sections in single page

Post by ooopie »

Thank you. It is possible with a single page and multiple content blocks, but it's not an idea solution in this case for a couple reasons:

- I would like the editors to easily add/remove/reorder "sections" of the main pages.
- Each "section" may have over 4-8 content blocks, and the main page may have 5 or more sections, so editing them all together could end up with 20-40 content areas on a single editor page. This would feel overwhelming.

I'm glad you pointed out CGContentUtils - very cool. That will end up being quite useful.

Now I just need to figure out a bit of code to capture the html output of a given content page -- all content blocks, processed through the assigned Core::Page template. Basically just what it sends to the browser, except I want to capture it and use it in another page template.
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: Multiple templated sections in single page

Post by PinkElephant »

ooopie wrote:It is possible with a single page and multiple content blocks, but [...]
- I would like the editors to easily add/remove/reorder "sections" of the main pages.
- Each "section" may have over 4-8 content blocks, and the main page may have 5 or more sections, so editing them all together could end up with 20-40 content areas on a single editor page. This would feel overwhelming.
So, it sounds like the second suggestion is more appropriate -- splitting the content across multiple pages. It's not what you're asking for but I'm imagining a master page template which does all the rendering -- and a series of sub-pages providing raw section content. N.B: using 'tabs' and 'priority' can significantly improve Editor usability:

Code: Select all

{content block='heading-fulltext' oneline=true label='Prominent heading' tab='Section 1'}
{content block='heading-col-01' tab='Section 1' label='Left column content'}
{content block='heading-col-02' tab='Section 1'}

{content block='Section 2' tab='Section 2'}
{content block='s2_image' tab='Section 2'}
You can also use CGContentUtils to add 'static text' in the template to provide explanations and/or, say, '<hr>' decoration at strategic points;

Code: Select all

{content_module module='CGContentUtils' block='admin_help_section01' tab='Section 1' priority=1}
The adding/deleting/sorting of section content could be achieved by letting Editors chose from a series of master templates and/or asking inline, in the master and/or sub-page templates using, say, CGcontentUtils dropdowns;

Code: Select all

	Section sort order
	[default]|0
	A, B, C|1
	C, B, A|2

Code: Select all

	Blue Box display option
	[Not shown]|0
	Show at top|1
	Show at bottom|2
(CGContentUtils Help cautions against the inline approach, I think). In either case, template inheritance should make the admin logic easier to manage.

I expect there is a way to do what you're looking at (capturing pre-rendered output) either invoking smarty directly and/or via modules -- but it feels unintuitive to me and I'm not sure how to do it.

Anyway, hopefully, there's food for thought until someone else chimes in.
ooopie
Forum Members
Forum Members
Posts: 10
Joined: Mon Dec 19, 2011 7:19 pm

Re: Multiple templated sections in single page

Post by ooopie »

Thank you all for the replies. I certainly learned some tricks I didn't know of that I will be using on this project.

I also found another thread which accomplishes exactly what I was looking to do here:
viewtopic.php?f=8&t=73662
(maybe not efficiently or securely)
Post Reply

Return to “CMSMS Core”