Page 1 of 1

How to Call Different Content Block Depending on Parent

Posted: Fri Nov 12, 2010 7:08 pm
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?

Re: How to Call Different Content Block Depending on Parent

Posted: Fri Nov 12, 2010 9:45 pm
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)?

Re: How to Call Different Content Block Depending on Parent

Posted: Fri Nov 12, 2010 11:17 pm
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()}

Re: How to Call Different Content Block Depending on Parent

Posted: Mon Nov 15, 2010 9:27 pm
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?

Re: How to Call Different Content Block Depending on Parent

Posted: Tue Nov 16, 2010 1:49 am
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}