How to programmatically get data inside a layout XML file in Magento

A while ago, I found myself trying to answer a question in Magento StackOverflow. It was a simple question: Can I get store config value in layout xml file?

http://magento.stackexchange.com/questions/23697/can-i-get-store-config-value-in-layout-xml-file/23702#23702

After some research, I realized that is possible to call a helper in a Magento tag inside an XML file the following way:

<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
<label>Site Map</label>
<url helper="catalog/map/getCategoryUrl" />
<title>Site Map</title>
</action>

The relevant part is

<url helper="catalog/map/getCategoryUrl" /> 

where catalog/map is the helper and getCategoryUrl is the action we are calling.

This has a lot of important applications. With this approach, anyone can get dynamic values from any Magento resource like a Model in a layout XML file and interact with blocks, change titles or create conditionals.

Mangento

Miguel Balparda has been developing Magento for almost four years. During this time, he has witnessed the exponential growth the platform has undergone; today it is one of the largest and most popular online stores in the world. There is a great deal of documentation and resources available for both merchants and developers. It is best to start by scanning the official Magento website, where you can find resources to get in touch with the application, as well as free extensions to learn the structure of modules. Miguel can be contacted at communications@santexgroup.com

 

Leave a reply

  1. Pingback: mortgagecrow.com