Aug 17, 2013
kalpesh

Magento debug XML (layout, config) files

In Magento if there is any error in XML file, Magento silently ignores it and continues further parsing. So you never get to know where is the actual error and makes it difficult to debug. You can’t even do any logging in XML file and also Magento don’t tell that error is in XML. It makes debugging almost impossible and ends up wasting in hours to find some silly mistake.

But we can know if there is any error in XML (layout.xml or config.xml or any xml file) if you use below code in the controller action which is being called. The browser will display WHOLE XML code and if it encounters any error in it, simply gives where is the error in the XML tree.

If you are trying to load let’s say Product View page, then put this code in Mage/Catalog/controllers/ProductController.php file’s viewAction() method temporarily to display whole XML tree to find out error(s) if any. As we are saying to display the page as XML, the page will break if it finds any mal-formed XML code and will show where is the mistake.

header("Content-Type: text/xml");
echo Mage::app()->getConfig()->getNode()->asXml();exit;

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

header("Content-Type: text/xml");
echo Mage::app()->getLayout()->getUpdate()->getHandles();exit;

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions