05.06.2025・TechStuff
05.06.2025・TechStuff

Magento 1: JSON in layout xml

Fabian Blechschmidt

Today I learned, one can use JSON in Magento 1’s layout xml.

Tell Magento which action parameter are json and that’s it.

You can tell Magento that only one parameter is json, like this. Then Magento decodes the json and uses it. I was very lucky to see it today, because I needed an array. With json no problem

<action method="setData" json="value"><key>some_data</key><value>setIt!</value></action>
<reference name="content">
        <block type="catalog/product_list_toolbar"
               name="product_list_toolbar"
               template="catalog/product/list/toolbar.phtml">
            <action method="setDefaultDirection"><param>desc</param></action>
            <action method="setAvailableOrders" json="order"><order>["created_at"]</order></action>
            <action method="setData"><key>_current_grid_order</key><param>created_at</param></action>
        </block>
    </block>
</reference>