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.

 
DanK replied on at Permalink Reply
Anyone?
adajad replied on at Permalink Best Answer Reply
adajad
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.
DanK replied on at Permalink Reply
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
adajad replied on at Permalink Reply
adajad
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.
DanK replied on at Permalink Reply
Sorry, bad wording on my part, that's what I meant! Thanks for all your help.
jordanlev replied on at Permalink Reply
jordanlev
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);
}
?>
Madebym replied on at Permalink Reply
Madebym
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:

<?php   $this->inc('elements/header_banner.php'); ?>
jordanlev replied on at Permalink Reply
jordanlev
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).
Madebym replied on at Permalink Reply
Madebym
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.