Can I avoid having two templates?
Permalink
Hi, hopefully this is an easy one for you c5 experts. On my homepage I have a header banner div at the very top the full width of the site. It should only be present on the homepage. Is there a way to do this without having to add an additional page type without that div resulting in having one template for the homepage and a different one for the rest of the site?
I'm afraid I can't see any obvious way to do this. Any help most appreciated.
Thanks.
I'm afraid I can't see any obvious way to do this. Any help most appreciated.
Thanks.

Anyone?
I would create an additional page type for this purpose. It's not that hard to do.
Go to 'Dashboard > Pages & Themes > Page Types' and click 'Add a Page Type'. Give it a name, a handle and the attributes you want to use.
Once the Page Type has been created you can add the default blocks to it.
Go to 'Dashboard > Pages & Themes > Page Types' and click 'Add a Page Type'. Give it a name, a handle and the attributes you want to use.
Once the Page Type has been created you can add the default blocks to it.
Thanks adajad, I just wasn't sure if there was a way of doing it while keeping everything on the one template so that template updates would only need done once.
Cheers, JP
Cheers, JP
You will still use the same theme template. A page type is just a different instance of the theme with it's own blocks on it.
Sorry, bad wording on my part, that's what I meant! Thanks for all your help.
You could put the code for the header area in a PHP "if" statement so it only appears on the home page. For example:
<?php if ($c->getCollectionID() == HOME_CID) { $a = new Area('Home Page Header'); $a->display($c); } ?>
I assume that jordanlev's solution is the best:), but i will post my way too.
In elements folder in your theme folder, create header_banner.php, put the banner inside and save the file.
Now in your default.php or home.php or anywhere you want, just call the banner with this:
In elements folder in your theme folder, create header_banner.php, put the banner inside and save the file.
Now in your default.php or home.php or anywhere you want, just call the banner with this:
<?php $this->inc('elements/header_banner.php'); ?>
Using elements in templates can be a very useful technique, but I don't think it answers this particular question (which was about how to avoid multiple page type templates, not about how to cleanly structure code).
Yes you are right, this technique would still involve at least 2 templates. I figured it out right after i posted yesterday, but somehow forgot to edit my post.