How to Call Different Content Block Depending on Parent

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
PorkyCorky
New Member
New Member
Posts: 9
Joined: Thu Sep 17, 2009 7:39 pm

How to Call Different Content Block Depending on Parent

Post by PorkyCorky »

Hello, I am trying to find a way to call a different content block depending on the parent of the current page.  For example, if Page X is under Parent Y then show GCB Z, else show GCB A.

I know I can do something similar using the page alias variable, but how I can do this using the page parent instead?
PorkyCorky
New Member
New Member
Posts: 9
Joined: Thu Sep 17, 2009 7:39 pm

Re: How to Call Different Content Block Depending on Parent

Post by PorkyCorky »

I work for a college, so lets say our pages are:

Home > Current Students > Admissions > Page

with every page being a child of Home.

So, would the first code show Admissions as the child of Admissions or Home?  I guess what I mean is, does root_alias refer to the very first parent (Home) or the closest parent (Admissions)?
Peciura

Re: How to Call Different Content Block Depending on Parent

Post by Peciura »

Sorry, i answered you as if you asked about root alias.
Luckily CGSimpleSmarty can return alias of parent page too.

Code: Select all

{$cgsimple->get_parent_alias()}
PorkyCorky
New Member
New Member
Posts: 9
Joined: Thu Sep 17, 2009 7:39 pm

Re: How to Call Different Content Block Depending on Parent

Post by PorkyCorky »

Hypothetically, let's say that I have this hierachy:

Home > Current Student > Admissions > Page

and I wanted to display a specific content for ALL the pages that are under Current Student.  Is there a way to do this?
Peciura

Re: How to Call Different Content Block Depending on Parent

Post by Peciura »

Try first smarty code if you store GCB name in extra content block(gcb_name). In case name of  GCB is not specified call default one.
{assign var='root_children' value='/'|explode:$content_obj->mHierarchyPath}
{if count($root_children)>1}
  {$cgsimple->get_page_content($root_children[1], 'gcb_name', 'foo')}{global_content name=$gcb|default:'default_gcb'}
{/if}
If there is some sort of connection between GCB name and page alias (GCB name == "gcb_prefix_$page_alias")
{assign var='root_children' value='/'|explode:$content_obj->mHierarchyPath}
{if count($root_children)>1}
  {global_content name="gcb_prefix_$root_children[1]"}
{/if}
If there is no obvious  connection among GCBs and pages
{assign var='root_children' value='/'|explode:$content_obj->mHierarchyPath}
{if count($root_children)>1}
  {if  $root_children[1]=='alias2'}
      {global_content name='gcb_1'}
  {elseif  $root_children[1]=='alias2'}
      {global_content name='gcb_2'}
{/if}
Post Reply

Return to “CMSMS Core”