Building a theme with multiple templates

Building a theme with multiple templates, a forum discussion on Jojo CMS. Join us for more discussions on Building a theme with multiple templates on our Themes Support forum.

Back to Forum Index : Back to Themes Support   RSS

22 Jan 2009
Posts: 1


i'm just trying to build a theme with different templates / layouts

is there any way of doing it nice
(having a choice of templates in the admin iface)

anything in planning?

the dirty way would be to put a smarty "if $pagetitle == something"-clause in the template.tpl and including the regarding tpl's.

a bit better would be to make a check like "if file_exists($page_name.tpl)" and include it otherwise use a default one.

still this way of handling it is not very felxible and breaks when the page name is changing...

anyone any experience with that?

Jaijaz Jaijaz

22 Jan 2009
Posts: 215

There are a number of ways to do this, of which I have used a couple depending on what I was trying to achieve.

Depending on who is the content administrator, remember that you may need to make sure that it is simple for them.

If you only have a couple of differences, like the homepage is different to the other pages then I find the {if $pageid==1} , as the home page is always 1, the best way.

The other thing to think about is that you could make the layout changes in the different plugins you have.

If however you have lots of different layouts and you would like the user to select then you could create different tpls and then add a field to the page table and then use their selection to dictate which tpl is used. Any field in the page table can be called up like this: {$fieldname}

Hope that helps.
If you not living on the edge you taking up too much space.



2 Feb 2009
Posts: 379

we mostly use two methods but both use the page table - add a new field:
eg: pg_template, easiest to make it an ENUM ('default', 'home', 'product')
so it will show up as a series of radio options in edit page

we do it often enough to build it into the basic theme we use a a starting point for sites

you can get Jojo to do this by including an 'install' folder in your theme, with a file called '' with the lines:
/* add the new template field if it does not exist */
if (Jojo::tableExists('page') && !Jojo::fieldExists('page', 'pg_template')) {
Jojo::structureQuery("ALTER TABLE `page` ADD `pg_template` ENUM( 'default', 'home' ) NOT NULL DEFAULT 'default';");

and in the the same install folder, add another file called '' with the lines:
$table = 'page';
$field = 'pg_template';
$default_fd[$table][$field]['fd_order'] = 7;
$default_fd[$table][$field]['fd_type'] = 'radio';
$default_fd[$table][$field]['fd_default'] = 'default';
$default_fd[$table][$field]['fd_name'] = 'Page Template';
$default_fd[$table][$field]['fd_help'] = 'Template to assign to this page (to be used in CSS styles)';
$default_fd[$table][$field]['fd_mode'] = 'basic';
$default_fd[$table][$field]['fd_tabname'] = 'Content';

which will make sure the new field shows up nicely in edit page when you run setup

then in your theme template use smarty ifs
eg {if $pg_template=='home'}
<p> something</p>
{elseif $pg_template=='product'}
<p> something else</p>
<p> something else again</p>

or if the differences between the layouts of the different page types can be achieved through css:
in the template set a css class on the body tag
<body class="{$pg_template}">

and then in style.css override your default styles
** default template **
#sidebar {width: 200px;float:right;}

** home template **
body.home #sidebar {width: 250px;float:none;}

** product template **
body.product #sidebar {display: none;}

or a combination of the above.

Back to Forum Index : Back to Themes Support   RSS
You must be logged in to post a reply

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