![]() |
![]() |
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?
cheers,
tim
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.
Jai
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 'install_page.inc.php' with the lines:
<?php
/* 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 'autoupdate_page.inc.php' with the lines:
<?php
$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>
{else}
<p> something else again</p>
{/if}
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 |
![]() |