Get template elements to only show when on certain page

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
jmmpc
Forum Members
Forum Members
Posts: 13
Joined: Wed Nov 10, 2010 8:31 am

Get template elements to only show when on certain page

Post 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. :)
User avatar
M@rtijn
Power Poster
Power Poster
Posts: 706
Joined: Sat Nov 14, 2009 4:54 pm

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

Post 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}
Make your community a better place!
jmmpc
Forum Members
Forum Members
Posts: 13
Joined: Wed Nov 10, 2010 8:31 am

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

Post 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
uniqu3

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

Post 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} 
Last edited by uniqu3 on Wed Jan 12, 2011 3:29 pm, edited 1 time in total.
jmmpc
Forum Members
Forum Members
Posts: 13
Joined: Wed Nov 10, 2010 8:31 am

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

Post 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
uniqu3

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

Post by uniqu3 »

Yeah i was replying to fast see below Edit:
Post Reply

Return to “Layout and Design (CSS & HTML)”