2

I'm using multistore and I have 2 website names. They are all using the same design package, so they share the same css file and template files, layout files etc.

I just need to add a class name in the body or html tag, a different one for each store.

So for example, for website 1:

<body class="website1">

and website 2:

<body class="website2">

I thought there might have been an option to add a class name for each website name in admin by either going to system>config>manage-stores and adding a class for each website or system>config>design then adding a class name for each website by changing the Current Configuration Scope. But looks like I have to do it by using the local.xml file. Is it possible to do it from the one local.xml file too, because both stores use the same local.xml file. Can anyone help me with it, thanks.

0

Magento body class has been render from function getBodyClass() of class Mage_Page_Block_Html and a for add a new body class,you need to use addBodyClass($classname).

Now using controller_action_layout_generate_blocks_after event/observer, you can add new class to body,because of after the layout block generate the addBodyClass() has been works.

Xml:

<frontend>
    <events>
      <controller_action_layout_generate_blocks_after> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_action_layout_generate_blocks_after_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento62889/observer</class> <!-- observers class alias -->
            <method>addbodyClass</method>  <!-- observer's method to be called -->
          </controller_action_layout_generate_blocks_after_handler>
        </observers>
      </controller_action_layout_generate_blocks_after>
    </events>
</frontend>

and Observer code is

<?php
class Stackexchange_Magento62889_Model_Observer
{

            public function addbodyClass(Varien_Event_Observer $observer)
            {
                $root = $observer->getEvent()->getLayout()->getBlock('root');
                if ($root) {
                    $storeCode = Mage::app()->getStore()->getCode();
                    $websitecode = Mage::app()->getWebsite()->getCode();
                    $root->addBodyClass($websitecode);
                }

            }

}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.