:::: MENU ::::

Create custom variables in Magento

Create custom variables in Magento
1 voto, 4.00 media (81% puntos)

One of the less commented features in Magento are the Custom Variables.

Much of the stores I see developed by others, don’t use this feature, but it’s the easiest way to store information from a custom extension or even custom data about our store. Let’s say for instance you need to put in the frontend the customer schedule.

The hard way for this would be adding some custom field in a custom extension that you can edit through the admin panel in the configuration section. Then, you shoul pull that var from config to the corresponding template.

The easy way would be to create a custom variable…

Custom Variables

… and then pull its value from a CMS page or block with:

{{CustomVar code="variable-code"}}

Or from anywhere in the code with any of these:

// Variable de tipo texto plano
echo Mage::getModel('core/variable')

// Variable con contenido html
echo Mage::getModel('core/variable')

Custom Varibles in Magento may have, as usual, global, store or store view scope so they are really usefull for storing quick data without an extension.


  • Responder Alejandro Cornejo |

    I try so hard to make it work the custom variable but everytime I put on a transactional email it prints the string textual

    echo Mage::getModel(‘core/variable’)->loadByCode(‘expiration_date’) ->getValue(‘html’);

    or the same without the echo if I remove it…

    • Responder Daniel Navarro Murillo |

      It is not possible to put php code inside the email templatess. You need to pass the variable as a template variable and then output its content by something like this: {{var myvarname}}

Hey! Qué opinas sobre el artículo?