I'd like to be able to set variables using the "Custom Layout Updates" box which appears under Manage Categories -> [Some Category] -> Custom Design
, to specify pieces of data which can be used in the category page template list.phtml
.
So far, I've tried using this:
<reference name="product_list">
<action method="setData">
<name>custom_banner_type</name>
<value>single</value>
</action>
<action method="setData">
<name>custom_banner_position</name>
<value>3</value>
</action>
</reference>
But when I try echo $this->getData("custom_banner_type");
inside list.phtml
the data is not available.
I've also tried getting the data inside the _beforeToHtml()
function inside List.php
, the template's controller, but this also does nothing!
So is there some way I can pass data/variables using the Custom Layout Updates XML? It has to be done through there, because the data will change for every single category so I can't use hard-coded layout files.
In which layout handle are you doing this? catalog_category_view
and catalog_category_layered
should be used.
Maybe you coul use the default Magento way for setting data with XML. Magento sets data in xml with the set function, which I find more readable than setData in XML.
Example:
<catalog_category_view>
<reference name="product_list">
<action method="setCustomBannerType"><value>single</value></action>
<action method="setCustomBannerPosition"><value>3</value></action>
</reference>
</catalog_category_view>
To retrieve the data you could use $this->getData('custom_banner_type');
but also $this->getCustomBannerType();
which is the same. If you want to know more about this I would suggest looking at magic methods (http://php.net/manual/en/language.oop5.magic.php)
I don't know if cache is enabled, if so flush the cache and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With