Combining 2 similar templates into 1 template

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
DoctorWho
Forum Members
Forum Members
Posts: 34
Joined: Mon Jan 24, 2011 5:14 pm
Location: USA

Combining 2 similar templates into 1 template

Post by DoctorWho »

I have two templates on my site with the only difference being the left-hand side bar.

Template A displays the upcoming events, while template B displays all of the child object in the parent category.

Is it possible to combined these template into one template with an if statement to determine what is displayed?

Something like:

Code: Select all


if current page is child

then

{menu start_level="2" collapse="1"}

else 

{cms_module module="CGCalendar" display="upcominglist" limit="12" unique_only="0" category="general"}

CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Combining 2 similar templates into 1 template

Post by Wishbone »

I'm assuming that you mean that you want it to show one thing if you are in a top-level page, and show something else if you're in a lower-level page?

Install CGSimpleSmarty. Put the following in your template:

Code: Select all

{* Get name of parent and put it in $parent *}
{$cgsimple->get_parent_alias($page_alias, 'parent')}

{* If I have a parent, then I'm at a lower level *}
{if $parent}
  {menu start_level="2" collapse="1"}
{else}
  {CGCalendar ...}
{/if}
DoctorWho
Forum Members
Forum Members
Posts: 34
Joined: Mon Jan 24, 2011 5:14 pm
Location: USA

Re: Combining 2 similar templates into 1 template

Post by DoctorWho »

Not just on the top-level page, but also on all of the lower-level pages.

Example:

On the information category there are 12 lower level pages on the left-hand side bar. I would like each of objects to be displayed when a user clicks on anyone one of them. Such as history, mission statement, etc..

Then have the Upcoming Events being displayed if the user is on a top-level page that doesn't have any lower level pages. Such as the Home, and Contact page.
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Combining 2 similar templates into 1 template

Post by Dr.CSS »

You could use {capture} and if empty show the other content...
DoctorWho
Forum Members
Forum Members
Posts: 34
Joined: Mon Jan 24, 2011 5:14 pm
Location: USA

Re: Combining 2 similar templates into 1 template

Post by DoctorWho »

I've revised the sudo code.

if active page (or current page) is parent and has child

then

display the child navigation objects

else

display upcoming events

So would this work than?

Code: Select all


{$cgsimple->get_parent_alias($page_alias, 'parent')}

{if $parent}

	<p id="heading">{$cgsimple->get_root_alias()}</p>	         

	{menu start_level="2" collapse="1"}

{else}

	<p id="heading">Upcoming Events</p>		         

	{cms_module module="CGCalendar" display="upcominglist" limit="12" unique_only="0" category="general"}

{/if}

CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Post Reply

Return to “CMSMS Core”