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?
How to Call Different Content Block Depending on Parent
-
- New Member
- Posts: 9
- Joined: Thu Sep 17, 2009 7:39 pm
-
- New Member
- Posts: 9
- Joined: Thu Sep 17, 2009 7:39 pm
Re: How to Call Different Content Block Depending on Parent
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)?
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
Sorry, i answered you as if you asked about root alias.
Luckily CGSimpleSmarty can return alias of parent page too.
Luckily CGSimpleSmarty can return alias of parent page too.
Code: Select all
{$cgsimple->get_parent_alias()}
-
- New Member
- Posts: 9
- Joined: Thu Sep 17, 2009 7:39 pm
Re: How to Call Different Content Block Depending on Parent
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?
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
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.
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}
{$cgsimple->get_page_content($root_children[1], 'gcb_name', 'foo')}{global_content name=$gcb|default:'default_gcb'}
{/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}
{global_content name="gcb_prefix_$root_children[1]"}
{/if}
{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}