0

So on a multistore Magento 1 we need to change the html on a page depending on the store, everything is done with one theme.

And we have 2 implementations, but I'm not sure which one is better.

First:

layout/local.xml

<tag_something_index>
    <reference name="something">
        <block type="something/text_list1" name="something.list.1">
            <block type="core/template" name="something.template.1" />
            <block type="core/template" name="something.template.2" />
        </block>
        <block type="something/text_list2" name="something.list.2">
            <block type="core/template" name="something.template.3" />
            <block type="core/template" name="something.template.4" />
        </block>
    </reference>
</tag_something_index>

Then I'd have the list block(s):

// List2 block has $storeCode !== 'something' and shows 3 & 4
class Ns_Something_Block_Text_List1 extends Mage_Core_Block_Text_List
{
    protected function _toHtml() {
        $this->setText('');
        $storeCode = Mage::app()->getStore()->getCode();
        if ($storeCode === 'something') {
            // we show something.template.1 & something.template.2
            return parent::_toHtml();
        }
    }
}

Of course, I could have just one block list and check a system config value set for the store -> Display Yes/No and match the layout child blocks names and get their html.

Second:

layout/local.xml

<tag_something_index>
    <reference name="something">
        <block type="something/text_list1" name="something.list.1">
            <block type="core/template" name="something.template.1" />
            <block type="core/template" name="something.template.2" />
        </block>
    </reference>
</tag_something_index>
<tag_something_index_new>
    <reference name="something">
        <block type="something/text_list2" name="something.list.2">
            <block type="core/template" name="something.template.3" />
            <block type="core/template" name="something.template.4" />
        </block>
    </reference>
</tag_something_index_new>

Then have the controller action:

class Ns_Something_SomethingController extends Mage_Checkout_Controller_Action
{
    public function indexAction()
    {
        $layout = $this->getLayout();
        $storeCode = Mage::app()->getStore()->getCode();
        if ($storeCode !== 'something') {
            $layout->getUpdate()->addHandle('tag_something_index_new');
        }
    }
}

Of course we could have a system config value.

Both pieces of code are working, although there might be mistakes here.

Layout & blocks should be cached by default, not sure about the impact with above conditions. From what I checked, block key is not generated per store (can add custom code if this is the best option).

First piece is using layout and blocks, second piece is using layout and controller. Which one is better and why, or is there another way to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.