Need to print all xml layout on frontend(index.php), because we want to check our custom xml handles were added or not.

Any one know technique to print.

  • Mage::app()->getConfig()->getNode(); try this
    – Amit Bera
    Jan 8 '15 at 7:20
  • Amit, i tried your code and found this code return config elements object. I am requiring xml layout. Your code return below output Mage_Core_Model_Config_Element Object ( [global] => Mage_Core_Model_Config_Element Object ( [install] => Mage_Core_Model_Config_Element Object Jan 8 '15 at 7:23
  • Mage::app()->getLayout()->getUpdate()->getHandles(); try this give current page handler
    – Amit Bera
    Jan 8 '15 at 7:23
  • Above code returns only current page handle used. output is : Array ( [0] => default [1] => STORE_default [2] => THEME_frontend_default_default [3] => catalogsearch_advanced_index [4] => customer_logged_out ) Jan 8 '15 at 7:26

You can get your hands on the full xml used as layout for a page in Mage_Core_Controller_Varien_Action::generateLayoutXml. This is the one that merges everything.
If you only need to print the xml for debug purposes from time to time, you can add this line in the method mentioned above just before the return statement.

echo $this->getLayout()->getNode();


echo $this->getLayout()->getXmlString(); //I recommend this one

If you want to build an extension, you can observe the event controller_action_layout_generate_blocks_after like this:

public function generateBlocksAfter($observer) {
    $xml = $observer->getLayout()->getXmlString();
    //do something with $xml ...print it, write it to a file....
  • Thanks Marius, below code is working echo $this->getLayout()->getXmlString(); Jan 8 '15 at 8:57
  • Thanks for this answer! just my two cents though: Mage::app()->getLayout()->getXmlString() Apr 5 '16 at 7:34
  • to print it even prettier: echo htmlentities($this->getLayout()->getXmlString()); Oct 22 '18 at 8:33

You can use the excellent layoutViewer created by Alan Storm for this. Using the module, you can output the handles for a page, or all the xml for the page layout.

Check the observer Alanstormdotcom_Layoutviewer_Model_Observer in his module for some examples:

$layout = $this->getLayout();

and more direct, for your want, simply output the handles used on the page:

private function outputHandles() {
            $update = $this->getUpdate();
            $handles = $update->getHandles();
            echo '<h1>','Handles For This Request','</h1>'."\n";
            echo '<ol>' . "\n";
            foreach($handles as $handle) {
                echo '<li>',$handle,'</li>';
            echo '</ol>' . "\n";
  • Thanks ProxiBlue, Your below code are working for me. $layout = $this->getLayout(); echo $node = $layout->getNode()->asXML(); Jan 8 '15 at 8:58

Hi You can current handler using blow code:

foreach ($Handles as $handle) : ?>
    <?php echo $handle ?>

  <?php endforeach ?>

We able to see the giant Xml tree by having

echo Mage::app()->getConfig()->asXml();

If you want to debug Layout Handles only, you can just check by this code:

echo Mage::app()->getLayout()->getHandles();

Tested : Magento ver.

Source : http://ka.lpe.sh/2013/08/17/magento-debug-xml-layout-config-files/

Source : http://ka.lpe.sh/2013/08/17/magento-debug-xml-layout-config-files/

echo Mage::app()->getLayout()->asXml();

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.