Magento Custom Variables

Custom Variables

Custom Variables is one of the features added in Magento v1.4 which receives little attention comparing to Secure 3D payment, Widget and WYSIWYG editor. What it is for? Think of each Custom Variable as a chunk of portable html content or plain text that you can insert into transactional email template, newsletter template, CMS page and static block.

Is Custom Variable useful and how an I use it?

If you have worked on transactional email template in previous versions of Magento, whether you are a Magento web developer or store owner, you will love this new feature as it takes away the tedious editing in each email template, it also make template update easier.

But why do I want to edit email template after it has already been setup?

The answer is, you should, and you want.

If you are a web developer making a Magento store for your client, setting a few Custom Variables in the email templates allow your client to update email content easily.

If you are Magento store owner, you can use Custom Variables for promotional marketing, e.g., offer a coupon code to guest checkout customer (this could be a good way to make the guest to become a returning customer); you insert the coupon code info in a pre-defined Custom Variable. You can use the same Custom Variable for a teaser ad, a reminder or a notice.

Since the release of Magento version 1.4, we updated all transactional email templates and have taken advantage of this new feature. Below image shows you the order email for the Tea and Herbs Co Magento theme which uses 4 Custom Variables, so that people who purchase our themes can setup their custom message easily, and we will guide you through the steps so that you can do it in your email template too.

tea and herbs co order email template

Step 1: Create Custom Variables

Go to your Magento Admin Panel, System > Custom Variables, add a new Custom Variable. From the above email template, you can see the four Custom Variables are marked as “A”, “B”, “C” and “D”. For “A” we called it store_hours and we entered the business hours.

create custom variable

From this screen shot, you can see a “Choose Store View” option, this menu will only show up after you have the Custom Variable saved, and when a store has chosen and saved, you will be presented a new option for “Use Default Variable Values” with Yes/No setting, we are however not sure how useful this option is because, according to our test, a Variable Code is unique and can only be used ONCE, whereas the “Identifier” used in CMS and Static Block, can be used many times for different stores, e.g., a “homepage” identifier for English Store, and another “homepage” identifier for Chinese Store; a “slideshow” identifier for static block assigned to English Store, and another “slideshow” identifier assigned to Chinese Store.

This means you need to assign different Variable Code for each language’s email template if you run a multi-language Magento store.

Now proceed to creating another 3 Custom Variables, name them anything you like, you can enter Variable HTML/Plain Value later if you haven’t decided what to write yet.

Step 2: Insert Variable Code to your email templates.

Go to your Magento Admin Panel, System > Transactional Emails, add a new template, after you have a template loaded, in the “Template Content” where the email content loaded, simply locate the place where you want the variable be placed, click on it so that it shows an “I” beam icon, then “Insert Variable…”, from the popup window, select the custom Variable accordingly. Proceed to inserting the rest of Variable Code. Repeat the steps for each email template.

This is one way of doing it. For our Magento theme matching email templates we do it differently , we insert the Variable code directly to the email template located in app/en_US/template/email, below screen shot shows you how.

create custom variable

The benefit for this approach, is that if you have only one Magento store, all you need is create the Custom Variable(s) you wish to use and off you go. You can skip the creation of transactional emails and you don’t need to assign email templates in System > Configuration. The draw back is that you must remember to backup the app/en_US/template/email so that it won’t get overwritten when you do Magento upgrade via Magento Connect.

Final Note

Custom Variables is for email template, newsletter template, CMS page and static block only, you cannot use it in PHTML template.

Tags :