Magento – passing a variable value to a CMS page using Layout Update XML

magento xml

In Magento I wanted to pass a variable or two from a CMS Page to my phtml template file. I wanted to do this as the client wanted backgrounds to change depending on the page, but there didn't seem to be anything on the web describing how to do this.

Found out it's remarkably easy :

1) Create your CMS page.

2) Go to Design -> Layout Update XML and enter the following:

<reference name="root">
<block type="core/text_list" name="ablock" as="ablock" translate="label">
<action method="setData"><name>bg_image</name><value>myimg.jpg</value></action>
</block>
</reference>

3) Edit your phtml page template (eg. app/design/frontend/base/default/template/page/1column.phtml) the code is then just :

<?php var_dump($this->getChild('ablock')->getData()); ?>

magento xml

hope that helps somebody out there.

 

Leave a Reply