9

To insert links in the CMS, we use this code:

<a href="{{store url='home'}}">home</a>

What is this "store" keyword doing and why is it called "store"?

And are there any other keywords available in place of store?

Is it also possible to write just the URL, without "store"?

If yes, what is the correct syntax?

10
  • What are you trying to achieve?
    – user487772
    Jun 24 '13 at 7:34
  • @Tim i want to know alternative way for insert link.
    – MageDev
    Jun 24 '13 at 7:47
  • 2
    Actually skin, and media are 2 different directives. One takes a file from the skin folder, and the same code can render 2 different images (depending on the theme) and media directive takes a file from the media folder. Why would you need an alternative to store directive? There is one, it works...case closed.
    – Marius
    Jun 24 '13 at 10:04
  • 2
    @Michel06 Actually this is the programming part of IT, where we hope there is only one method for performing a given task. In this case, the {{store url=""}} directive will get you a link.
    – benmarks
    Jul 1 '13 at 12:28
  • 1
    @zus you can use a condition like given below. {{if order.customer_group_id == 1}} <p>Test Code</p> {{/if}}
    – MageDev
    Mar 19 '20 at 10:28
7

Magento Syntaxes to use URLs in CMS Content:

  • get SKIN URL: {{skin url='images_foldername/image_name.jpg'}} - get image from skin folder of configured theme package
  • get Media URL: {{media url='magento-image.jpg'}} - get image from media folder
  • get Store URL: {{store url=''}}magento-page.html - get domain URL of working store
  • get Base URL: {{base url=''}}magento-page.html - get domain URL of base website.
1
  • magento-page.html should be inside the directive in the url='...' or direct_url='...'.
    – 7ochem
    Jul 28 '17 at 9:21
21
+50

As explained in Where is the code for "{{store url="example/example"}} {{store}} is one of the so-called template directives used by CMS and transactional emails

It is documented as follows:

/**
 * Retrieve store URL directive
 * Support url and direct_url properties
 */

So, "store" is short for "store url" and refers to an URL in the store, that means a link within the store. It automatically adds the correct base URL (important for email templates where you cannot use relative links) and resolves some other parameters (see below)

How to use it

You can pass it a route, just as you would with Mage::getUrl():

{{store url="customer/account/login"}}

Also with parameters:

{{store url="catalog/product/view" id="42"}}

Or query parameters, for example to add filters in the layered navigation:

{{store url="catalog/category/view" id="3" _query_color=red}}

=> example.com/url-to-category-3/?color=red

If you want to specify an arbitrary URL instead, use direct_url, this way Magento only adds the base URL and leaves the given URL as it is:

{{store direct_url="terms.html#delivery"}}

Other URL directives are

  • {{skin url="..."}} for URLs to images, JavaScript or CSS within the current theme, using the theme fallback mechanism.
  • {{media url="..."}} for URLs to images or other media in the media directory (default: /media/)
  • {{protocol url="www.domain.com/"}} for arbitrary external URLs, but with the current protocol (http or https)
  • {{protocol http="http://url" https="https://url"} to show different URLs dependend on the current protocol
  • {{protocol}} to just output "https" or "http"

Other non-URL directives

  • {{config path="..."}} outputs a configuration value
  • {{customvar code="..."}} outputs a custom variable (globally maintained in System > Custom Variables)
  • {{htmlescape var="..." allowed_tags="..."}} converts special characters in the text, given in "var" to HTML entities. The optional "allowed_tags" parameter can contain a comma separated list of tags that should be kept intact (for example "h1,h2,strong,em"). It is most useful in email templates because you can pass a template variable: like this: {{htmlescape var=$customer.firstname}}
  • {{inlinecss file="..."}} loads CSS from a file and adds it as inline style sheet. Useful for emails.
  • {{block type="..." id="..." output="..." ...}} instantiates and renders any Magento block type
  • {{layout area="..." handle="..." ...}} loads an entire layout handle (defined in the layout XML files) and renders its first block. Additional parameters are passed to all blocks.

Note that custom variables and blocks must be whitelisted before they can be used. See: APPSEC-1057 How to add variables or blocks to the white list tables

Other non-URL directives (Email Templates only)

  • {{var X}}, {{var X.y()}} output template variable X / result of method y() on variable X. See Template vars/placeholders
  • {{depend X}}...{{/depend}} output content in between only if variable X is true-ish (note that you cannot use logical expressions here, just variables or methods on variables. {{if X}}...{{else}}...{{/if}} the same but with an optional "else" block.
  • {{template config_path="..."}} include another email template based on a configuration value, for example "design/email/header". By default, the "header" and "footer" email templates are included in all other email templates.
  • {{include template="..."}} includes another template. This template will inherit all template variables from the current one and you can pass additional parameters with name="value".

Variables in parameters

Anything that can be processed by {{var}} (see above), can also be used as parameter for another directive, with the following syntax:

{{store url=$x}}
{{store url=$x.y()}}

Limitations

  • You cannot nest {{if}} and {{depend}} directives:

      {{if x}}{{depend y}}     THIS WORKS    {{/depend}}{{/if}}
      {{depend x}}{{if y}}     THIS WORKS    {{/if}}{{/depend}}
    
      {{depend x}}{{depend y}} DOES NOT WORK {{/depend}}{{/depend}}
      {{if x}}{{if y}}         DOES NOT WORK {{/if}}{{/if}}
    
  • You cannot use directives in parameters of other directives. For example:

      {{store url={{config path="..."}}}}
    

    does not work

Where to find these directives/parameters

The class Mage_Core_Model_Email_Template_Filter is responsible for parsing most of the attributes specified in CMS directives ({{). This class is commonly inherited from other classes like Mage_Widget_Model_Template_Filter and Mage_Cms_Model_Template_Filter.

For example: Mage_Core_Model_Email_Template_Filter::storeDirective, Mage_Core_Model_Email_Template_Filter::skinDirective, Mage_Core_Model_Email_Template_Filter::htmlescapeDirective and so on.

There you can see what attributes you can specify. For example in the skinDirective method:

    public function skinDirective($construction)
    {
        $params = $this->_getIncludeParameters($construction[2]);
        $params['_absolute'] = $this->_useAbsoluteLinks;

        $url = Mage::getDesign()->getSkinUrl($params['url'], $params);

        return $url;
    }

So we can use: {{skin url="someimage.jpg" _theme="default" _package="default" _area="frontend"}}

2
  • {{store url="customer/account/login"}} this is also work on M2
    – Goldy
    Sep 28 '16 at 19:30
  • I just want to add if-else condition inside my app/locale/en_US/template/email/sales/order_new.html code => paste.ofcode.org/GKsBaztggNpXrmSws7cEyG line 30 - 40, any help thanks @Fabian Schmengler
    – zus
    Mar 17 '20 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.