Magento: Get a custom variable value in a phtml file

I think custom variables were originally designed to be used in emails but I use them within the main site for little bits of information whose value needs to change on a per store/language basis.

This is how you get a custom variable inside a phtml file:

Mage::getModel(‘core/variable’)->setStoreId(Mage::app()->getStore()->getStoreId())->loadByCode(‘[variable-code]’)->getValue(‘plain’);

You can create and set these custom variables in the admin via the system>custom variable menu.  Note that you can’t set values for different stores/languages until you have saved your initial value.  Going in to edit it once saved will allow you to change the values per store.

I use this as a sort of cheaters way of having some controllable values available in the admin without creating proper configuration values in modules and that sort of thing.

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *