Magento 1.9 – Using Custom Variables in Category Description

categorycustom-variableglobal variablemagento-1.9

I recently created a custom variable named storecount – which I'll be programatically increasing for every store that is added to my store locator plugin.

I'd like to show this in various locations including product and category descriptions so when we do add a new store, we're not having to find every occurrence of the store count and manually increase it by 1.

Using {{customVar code=storecount}} doesn't work in category descriptions. Is there any way I can get this variable without hacking the Magento core to pieces?

Best Answer

The easiest way to do it, is to use the same template processor for category description as it is used for the cms blocks and pages content. The one from the widget module.
For this you need an extension. Let's call it StackExchange_Catalog.
You will need the following files.

app/etc/modules/StackExchange_Catalog.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Catalog>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
                <Mage_Cms />
                <Mage_Widget />
            </depends>
        </StackExchange_Catalog>
    </modules>
</config>

app/code/local/StackExchange/Catalog/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <global>
        <catalog>
             <content>
                <tempate_filter>widget/template_filter</tempate_filter>
            </content>
        </catalog>
    </global>
</config>

clear the cache and try again.

Related Topic