Posted on | May 28, 2013 | No Comments
Ah the strength and failings of Magento. Of all its features, the ability to control nearly all of the layout from a single local.xml file is my favourite. One of the main features of this approach is that you can call functions (called actions) to add, remove or override values for the block you are working on. But what is the correct way to specify the value?
To maintain readability I have been taught to indent each block of xml, such as the below:
On the block that this xml is located, Magento will call the function ‘addCss’ and pass in an array with the key ‘stylesheet’ and the value of ‘css/styles.css’.
The problem with the above is that Magento kindly reads all the white space as well as the actual value that I want to pass into the function, meaning that the value passed into the function is actually ‘ css/styles.css’. When it comes to rendering the stylesheet, we get:
This, of course, will not load the css file.
The correct way (if you haven’t worked it out) is to not indent the values:
It may not be as readable to you or me, but Magento will now read the value correctly.
Magento sucks as it does not trim the values that are passed from the xml files into the called functions. As such, we need to enter the values inline with the parameter tags.
Posted By:Richard Parnaby-King