Magento Custom Variables

July 12th, 2016

Warning: This post is 7 years old. Some of this information may be out of date.

Magento provides an interface for you to define your own custom variables. You can use these in CMS pages, static blocks, email templates and phtml templates. Here's how to use them.

Defining Custom Variables

You can add custom variables in the admin area. Go to 'System > Custom Variables'.

For example, we're going to create a custom variable to output a link to this blog. Fill in the fields as follows:

  • Variable Code: euperia_blog_link
  • Variable Name: Euperia Blog Link
  • Variable HTML Value: <a href="">Visit</a>
  • Variable Plain Value: Visit

Defining Magento Custom Variables\

Save this.

Using Custom Variables in CMS page and Static Blocks

To use our new custom variable in a CMS page or a static block we add the following markup:

    {{ customVar code=euperia_blog_link }}

Using Custom Variables in PHTML Templates

To use the custom variable in a phtml template we need to load it, specifically defining the HTML or Plain value:

    $customHtml = Mage::getModel('core/variable')
    $customPlain = Mage::getModel('core/variable')
    echo $customHtml;
    echo $customPlain;