Markup Tags - CMS Directives

Last modified by jkragh on Thu, June 24, 2010 16:24
Source|Old Revisions  

This is an old revision of the document!

This article details which template tags can be used on CMS pages, in static blocks, and in email templates.

What is a template tag?

A template tag is a bit of text surrounded by double curly braces which has a special meaning to Magento (e.g., {{store url=""}}). You can use a template tag to create a link to a page within your store without having to type out your domain name. You can also use a template tag to embed a block within a page without editing layout or template files. Template tags have a variety of uses.

Where can I use template tags?

You can use template tags on CMS pages, in static blocks, and in email templates.

How do I use template tags?

Simply enter the template tag in one of the places Magento recognizes it (see above).

To illustrate, say you wanted to display your company’s “About Us” image on your store’s home page. (You manage the content of the home page by navigating to CMS > Manage Pages and then clicking on “Home page” in the backend.) You might do this by typing

  1. <img src="" />

but that’s a lot to type. Instead, using a template tag, you could simply say

  1. <img src="{{skin url='images/media/about_us_img.jpg'}}" />

Which tags can I use?

Note: In the following examples I’m assuming that a working Magento install is set up at

You can use the following tags:

{{block type='module/package_classname' template='path/to/template.phtml'}}

This inserts a block of the type module/package_classname using the template path/to/template.phtml. The string module/package_classname translates into a class name which is defined in the Block directory of module. (Thus core/text_list, for instance, translates into Mage_Core_Block_Text_List, which is defined in app/code/core/Mage/Core/Block/Text/List.php.)

If the module’s Block directory contains no sub directories, the package_ part of the string is omitted. (Thus the string tag/popular translates into Mage_Tag_Block_Popular, which is defined in app/code/core/Mage/Tag/Block/Popular.php.)

The value of the template attribute should be the path to the template that corresponds to the block, starting from the theme directory (e.g., tag/popular.phtml).

{{htmlescape var='' allowed_tags=''}}

Escapes all HTML tags in the value of the var attribute, except for those specified in the value of the allowed_tags attribute. (The latter expects a comma separated list of allowed HTML tags). To illustrate,

{{htmlescape var='<a href="javascript:alert(1);">Hello</a>'}}

gets converted to <a href=”javascript:alert(1);”>Hello</a>, i.e., an escaped string which the browser won’t execute.

{{layout handle=''}}

Inserts HTML layout output. The handle attribute expects the name of a layout handle, e.g. default.

{{media url=''}}

Inserts the URL of the media directory, e.g., Changing the value of the url attribute to a non-empty string will cause the string to be appended to this URL. Thus,

{{skin url='catalog/product/l/a/large_phone.jpg'}}

will be converted to

{{skin url=''}}

Inserts the URL of the current theme’s skin directory, e.g., Changing the value of the url attribute to a non-empty string will cause the string to be appended to this URL. Thus, if you were using the default theme and the default interface, then

{{skin url='images/media/about_us_img.jpg'}}

will be converted to

{{store url=''}}

Inserts the store’s base URL, i.e., the URL of the store’s home page. (Sample output: Changing the value of the url attribute to a non-empty string will cause the string to be appended to the store’s base URL and a slash (/) to be tacked on to the end of the resulting URL. Thus,

{{store url="about-magento-demo-store"}}

will be converted to Note the terminating slash. This is what distinguishes the url attribute from the direct_url attribute: using the former, the resulting URL will always end with a slash. The url attribute, therefore, should be used to reference directory-like paths, e.g. customer/account.

{{store direct_url=''}}

Does the same as {{store url=""}} but without appending a slash to the resulting URL. This should be used to reference file-like paths, e.g. coffee/kona-fancy-whole-bean.html.

How do template tags work?

This is roughly what happens when Magento encounters a template tag it understands:

  1. Magento uses the tag to populate an array with three elements. The first element is the whole tag (e.g., {{store url="coffee/test.html"}}). The second element is the keyword which follows immediately after the opening curly braces (e.g., store). The third element is the tag’s keyword=value pair (e.g., url=”coffee/test.html”).
  2. Magento passes the array to a method of the Mage_Core_Model_Email_Template_Filter class. The name of the method depends on the keyword within the tag: if the keyword is store, for instance, the storeDirective method will be called.
  3. The method returns a value. This value is used instead of the template tag on the front end.


Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs