You may be familiar with some of the template directives you can use in the Magento CMS pages and blocks. Their syntax is distinguished by the double curly braces that enclose the directives. Did you know you can also use these directives in Product pages and Categories as well.

Today, we’ll have a quick look at the store directive used to generate store URLs and the parameters you can pass to it.

You’ve probably seen the most common one:

[sourcecode language=”php”]<a href="{{store url=""}}">Go to home page</a>[/sourcecode]

But you may not be aware of the different parameters you can pass to the store directive when creating store URLs.

The parameters of interest are:

  1. url
  2. direct_url
  3. _query
  4. _query_[name]

Let’s have a look at each of those.

1. url

The url paramter generates a URL using the Magento routing. This means it will take anything you pass to the store url directive append it to the store base URL and append a ‘/’. So for example, you can create a URL to the contact us page like so:

[sourcecode language=”php”]<a href="{{store url="contacts"}}">Contact Us</a>[/sourcecode]

Resulting in a URL like http://yourstore.com/contacts/.

2. direct_url

If you need to create a URL to a category or product, you can use the direct_url parameter. In that case, whatever you pass to the store directive will simply be appended to the base URL. For example, if your settings are that .html is added to your links, a link to a category can be created like so:

[sourcecode language=”php”]<a href="{{store direct_url="category/subcategory.html"}}">Our Latest Range</a>[/sourcecode]

3. _query and 4. _query_[name]

If you need to generate URLs with query parameters, there are two ways Using the _query parameter, you can add an arbitrary query string to the URL like so:

[sourcecode language=”php”]<a href="{{store direct_url="category/subcategory.html" _query="a=param_a&amp;b=param_b"}}">Our Latest Range</a>[/sourcecode]

Or you can use the second parameter syntax where you define the query parameter name with the parameter itself:

[sourcecode language=”php”]<a href="{{store direct_url="category/subcategory.html" _query_a="param_a" _query_b="param_b"}}">;Our Latest Range</a>[/sourcecode]

This results in the same URL as the previous example:
http://yourstore.com/category/subcategory.html?a=param_a&b=param_b