Different Templates

Different Templates, a forum discussion on Jojo CMS. Join us for more discussions on Different Templates on our General Discussion forum.

Back to Forum Index : Back to General Discussion   RSS
lynchpin

9 May 2008
Posts: 60

Just started using Jojo today, and have a general question that I can't seem to find an answer to in the documentation or forums.
What is the easiest way to use a different template file on my homepage as on the subpages?
Most of my client's sites have a very different homepage from the general subpage. So, ideally I would like to have in the 'mysite->themes->templates' folder two files:
homepage.tpl
subpage.tpl
Then be able to choose which template for which page?
Thanks!
Harvey

Core Developer

Harvey

9 May 2008
Posts: 327

Hi and welcome.

The best way of differentiating content is to use an {if} statement in the template. Rather than having 2 completely different templates, probably what you want is a single template with a few sections that are different.

For homepages, you test against the "pageid" being "1".

Consider these examples...
//Use a different header image on the homepage
<img src="images/{if $pageid==1}home.jpg{else}other.jpg{/if}" alt="" />


//include some extra HTML on the homepage only
{if $pageid==1}
<div>foo bar</div>
{/if}


//Use a different sub-template for the homepage
//Note you will need to create these .tpl files in your templates folder
{if $pageid==1}
{include file="homepage.tpl"}
{else}
{include file="rest_of_site.tpl"}
{/if}


Hopefully that's reasonably straightforward. We find using if statements better than repeating the whole template, makes for much less duplication.

If you want to test against other pages, the "pg_url" field is a good one to use. Consder the following code as a way of using different sidebars on a site...

<div id="sidebar">
{if $pageid==1}
{include file="sidebar_home.tpl"}
{elseif $pg_url=='our-team'}
{include file="sidebar_team.tpl"}
{elseif $pg_url=='contact'}
{include file="sidebar_contact.tpl"}
{else}
{include file="rest_of_site.tpl"}
{/if}
</div>


Hope this helps.
lynchpin

9 May 2008
Posts: 60

Great! That makes sense. That's along the lines of what I was going to do, but wanted to make sure I wasn't missing some easy method.

So far I'm loving this CMS. I currently have my own CMS that is way outdated so I'm hoping to migrate to Jojo.

Thanks for the help here!
Back to Forum Index : Back to General Discussion   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.