Page 1 of 1

Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 2:55 pm
by jmmpc
Hi, I have searched around and so far not found anything that covers what I am looking for.

I am trying to create a template with a sidebar. On that side bar I will have some elements, for example I will have a navigation menu and a mail shot signup box. I can create the template with sidebar fine, however I would like to get certain parts of the template to only show when on certain pages of the website.
For example:
1) When navigating the "Home Users" page on our website, I would like the mailshot signup box to display the signup to the home users mailing list in the side.
2) When navigating a different section of the website, e.g Support, I don't want the mailshot signup box to display in the sidebar at all.

I would like some sort of 'if' statement. So {if page=home display(<div>Some content for home users</div>)} {else if page=business display(<div>Some content for business users</div>)}
Perhaps someone could give me some ideas.
Many thanks. :)

Re: Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 3:03 pm
by M@rtijn
Your were already on the right track ;)

{if $page_alias eq 'name_of_page'}
do something
{elseif $page_alias eq 'name_of_page2'}
do something else
{else}
do nothing
{/if}

Re: Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 3:10 pm
by jmmpc
Wow, super quick response there, thank you M@rtijn, I will try that for individual pages.

What about if I want all child pages of a parent page to be included in the 'if' statement, is that possible.
Eg a page structure like this:

1.Home User
1.1 Welcome
1.2 Support
1.3 Contact
2. Business User
2.1 Welcome
2.2 Support
2.3 Contact

So that all the pages under the [2. Business User] parent, are given the content of the 'if' statement.

Regards

Re: Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 3:21 pm
by uniqu3
{if $page_alias eq 'name_of_page'}
{menu template='yourtemplate' childrenof=$page_alias}
some other content
{elseif $page_alias eq 'name_of_page2'}
{menu template='yourtemplate' childrenof=$page_alias}
some other content
{else}
do nothing
{/if}

or

{if $page_alias eq 'name_of_page'}
{menu template='yourtemplate' start_level='2'}
some other content
{elseif $page_alias eq 'name_of_page2'}
{menu template='yourtemplate' start_level='2'}
some other content
{else}
do nothing
{/if}

Edit: ok after reading your question for the second time i think i misunderstood what you were after, so i think this below is what you want:

Install CGSimpleSmarty Module
In your Template you can do something like:

Code: Select all

{$cgsimple->get_page_title($cgsimple->get_parent_alias(), 'parent_page')}
{if ($page_alias eq 'name_of_page') or ($parent_page eq 'name_of_page')}
some other content
{elseif ($page_alias eq 'name_of_page2') or ($parent_page eq 'name_of_page2')}
some other content
{else}
do nothing
{/if} 

Re: Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 3:28 pm
by jmmpc
Hi uniqu3
Sorry I am a little confused. Is that coding for my first question or my second?
I don't want to actually display a menu list. I just want the content in the if statement to appear for all child pages of a defined parent page.
Regards

Re: Get template elements to only show when on certain page

Posted: Wed Jan 12, 2011 3:30 pm
by uniqu3
Yeah i was replying to fast see below Edit: