WackGet
WackGet

Reputation: 2916

Magento: different home page for each theme, but using same store view, and without changing URL?

I've recently developed a new mobile theme for my Magento site, containing different CSS/JS/layout/template files than the normal desktop theme.

I'm using Magento's "matched expression" feature in the Design section to switch to the mobile theme if a mobile user-agent string is detected.

I'd like the mobile site to have a different home page than the desktop one, but both themes are running off the normal store view, so I'm not sure how to do this.

Is it possible to set a different home page on a per-theme basis, as opposed to per-store-view?

So if Desktop User navigates to www.example.com/, they'll see CMS Page "home", but if Mobile User navigates to the same URL, they'll see CMS Page "mobile-home"?

Upvotes: 1

Views: 4121

Answers (3)

WackGet
WackGet

Reputation: 2916

I ended up experimenting with Marius' suggestion above, and edited cms.xml to override the index page (i.e. home page) with my own template, which worked:

<cms_index_index translate="label">
    <reference name="content">
       <block type="catalog/navigation" name="alternative_home" template="alternative_home.phtml" />
    </reference>
    <remove name="cms.wrapper"/>
</cms_index_index>

You might also wish to try overriding cms_index_defaultindex too.

Upvotes: 1

Peter A
Peter A

Reputation: 374

@Marius answer is correct, when only considering a stock Magento install, you cannot separate layouts for CMS pages, however having said that, Magento is still OOP and PHP so there is a way to set up a facility to do what you want.

The trick to it is to creating a custom layout handler that gets added to the CMS's page layout, that way, you can specify what content you want on a page through a layout.xml file.

I have done this myself, so it is possible.

Create a custom module that has a layout file and an observer model with a function that you can trigger on the following event.

<controller_action_layout_load_before>

This function can then be used to determine what page you are on. This is the code that I used in the function to inject a layout handle (this could be greatly improved for better scalability)

// Triggered on the controller_action_layout_load_before Event
public function addCustomHandles( $observer ) {
    $update = Mage::getSingleton('core/layout')->getUpdate();

    if ( Mage::app()->getFrontController()->getRequest()->getModuleName() == 'cms' ) {
        $update->addHandle( 'cmslayouthandler_cms_page_' . Mage::getSingleton('cms/page')->getIdentifier() );
    }
}

This function gets the layout singleton, confirms it is on a CMS page, and the constructs a handler based off of the currently selected page. It would add a handler like the following:

'cmslayouthandler_cms_page_home'

You will then be able to update the layout for that page in the modules layout file that you created, kinda like this:

<layout version="1.0.0">
<cmslayouthandler_cms_page_home>
    <reference name="content">
        <block type="core/template" name="home_page" template="page/template/home.phtml" />
    </reference>
</cmslayouthandler_cms_page_home>
</layout>

Take into consideration that CMS pages created through the Magento Admin Panel require a value in the 'Content' section, you can easily place a blank dummy value or zero out the value through the DB directly, I prefer the first method personally.

Good Luck!

Upvotes: 2

Marius
Marius

Reputation: 15206

You cannot have 2 homepages on the same store view.
But you can add the content of both your pages content on the same page and just hide the own that's not needed. If you are on mobile hide the desktop content and the other way around.

Upvotes: 0

Related Questions