7

I want to make changes in cms page's content dynamically before page load on front-end.

16

As every request is processed through a controller in Magento we'll start from Mage_Cms_PageController where we see that the cms/page helper actually renders the page.

This is done in the method _renderPage. In this method we'll find the Event cms_page_render on line 107. This event gives you, among other objects, the page object.

This object contains all the data of your page. Now you can observe this event from your custom build extension by adding it to the config.xml

<?xml version="1.0"?>
<config>
  <global>
    <events>
      <cms_page_render>
        <observers>
          <your_extension_cms_observer>
            <type>singleton</type>
            <class>Your_Extension_Model_Csm_Observer</class>
            <method>changeContent</method>
          </your_extension_cms_observer>
        </observers>
      </cms_page_render>     
    </events>
  </global>
</config>

This will call the class Your_Extension_Model_Csm_Observer, method changeContent which should look something like this

class Your_Extension_Model_Csm_Observer
{

    public function changeContent($observer)
    {
      $event = $observer->getEvent();
      $cms_page = $event->getPage();   

      [...]
    your code goes here
      [...]

      return $this;
    }
}

For more info about observers check this Wiki page

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.