Richard Parnaby-King

Web Developer – PHP, Zend Framework and Actionscript 3

Posted on | | 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:

[xml]

css/styles.css

[/xml]

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:

[html] [/html]

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:

[xml]

css/styles.css
[/xml]

It may not be as readable to you or me, but Magento will now read the value correctly.

Conclusion

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:

Comments

  • ABOUT

    Having fifteen years of programming experience in PHP, Zend Framework and ActionScript3, I have a very strong working knowledge of object orientated programming.

    I am a PC Gamer! Playing FPS, RTS, RPG and the occasional MMO since 1996 I have a huge number of a variety of fast-paced games.

  • Recent Posts

  • Categories

  • SUBSCRIBE TO OUR FEED