1

I have two different themes one for desktop and one for mobile. I added about-us page content in cms pages. Its working fine in desktop.

Now, the html is different for mobile theme. So, how can I place mobile theme code in the same editor? The content should load based on theme. How can I get frontend theme and write conditions in cms editor.

ex: if(theme = "desktop") { desktop about us page should render } else { mobile about us page should render }

  • have you use multiple store ? – Amit Bera May 1 '15 at 10:34
  • no, same store but different themes. – lakshmi May 1 '15 at 12:55
  • can you please show code of editor thus i can understrand – Amit Bera May 2 '15 at 4:47
1

You can do this using Event observer

On controller_action_predispatch_cms_page_view

On this event check current theme by $Currenttheme=Mage::getSingleton('core/design_package')->getTheme('layout'); on observer and then redirect from here according to your logic.

config.xml

<global> 
    .....
     <events>
    <controller_action_predispatch_cms_page_view> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_action_predispatch_cms_page_view_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento65420/observer</class> <!-- observers class alias -->
            <method>addRedirection</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </controller_action_predispatch_cms_page_view_handler>
        </observers>
      </controller_action_predispatch_cms_page_view>
    </events>
    ...
</global>

Edited:

Use: cms_page_render Event

Better way to use cms_page_render event and fire an observer this.

config.xml code like:

  <global>
    <models>
      <magento65420>
        <class>Stackexchangetwo_Magento65420_Model</class>
        <resourceModel>magento65420_mysql4</resourceModel>
      </magento65420>
    </models>
    <events>
      <cms_page_render> <!-- identifier of the event we want to catch -->
        <observers>
          <cms_page_render_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento65420/observer</class> <!-- observers class alias -->
            <method>addRedirection</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </cms_page_render_handler>
        </observers>
      </cms_page_render>
    </events>
  </global>

Then using observer parameters page object and current controller redirect to home page.

<?php
class Stackexchangetwo_Magento65420_Model_Observer
{

            public function addRedirection(Varien_Event_Observer $observer)
            {
                 // Mage::dispatchEvent('cms_page_render', array('page' => $page, 'controller_action' => $action));
                 $controller=$observer->getEvent()->getControllerAction(); // Current controller
                 $page=$observer->getEvent()->getPage();// page object 
                 echo  $CurrentTheme=Mage::getSingleton('core/design_package')->getTheme('layout');
                    if($CurrentTheme=='default' && $page->getId()==6){          
                     $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
                     $controller->getResponse()->setRedirect(Mage::getUrl());
                    }

            }

}
| improve this answer | |

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.