SpinOneSolutions | I waste my time so that you don’t have to…

Apr/10

16

Magento CMS Tags (Directives)

Here is, I think, a comprehensive list of tags (directives) available for use within the Magento CMS.  You can use these either in static blocks or CMS pages.

Magento: Enterprise ver 1.6.0.0

block

Description
Outputs a virgin block or loads a defined block.

Parameters
type : Type of block to be created.
id : Id of block to be created.
output : The block instance method to call after creation.  If blank “toHtml()” will be called by default.
<parameter> : Any additional parameters will get key value pairs set in the block’s Data array.

Usage
{{block type=”cms/block”}}
Results in a virgin static block with no data.

{{block id=”myBlock”}}
Results in an instance of myBlock.

{{block id=”myBlock” param1=”foo” param2=”bar”}}
Results in an instance of myBlock with a data array containing key value pairs param1=>”foo” param2=>”bar”.

{{block id=”myBlock” output=”myMethod”}}
Results in an instance of myBlock after it has called member method myMethod.

Note that if you already HAVE a block with this particular ID than it will be loaded.  This is great if you want to include a static block into a CMS page or into another static block!  Just create the block in the CMS section of admin and use the ID that you set.

Any parameter that your block class is sensitive too will work as well.  For example:

{{block id=”myBlock” template=”customfolder/customTemplate.phtml”}}
Results in an instance of myBlock using a custom template.

layout

Description
Outputs the contents of the defined layout.

Parameters
area : The area to load.  If blank the layout’s default area will be used.
handle : The layout handle to load.
<parameter> : Any additional parameters will get key value pairs set in the layout’s Data array.

Usage
{{layout handle=”default”}}
Outputs the default layout handle.

skin

Description
Outputs the url for a resource in the current skin.

Parameters
url : The url to reference within the current skin directory.
<parameter> : Any additional parameters will be passed to the getSkinUrl() method.

Usage
{{skin url=”images/myimage.gif”}}
Outputs: http://www.mydomain.com/skin/frontend/default/default/images/myimage.gif
Note: This assumes the current theme and skin are default.

media

Description
Outputs the Base Media URL.

Parameters
url : The url to prefix with the base media url.

Usage
{{media url=”images/myimage.gif”}}
Outputs: http://www.mydomain.com/media/images/myimage.gif
Note: This assumes Base Media URL is set to http://www.mydomain.com/media (See Admin->Configuration->Web)

store

Description
Outputs the store specific Base URL.

Parameters
direct_url : The url to prefix with the Base URL.  Note this method does NOT assume internal routing.
url : The url to prefix with the Base URL.  Note this method DOES assume internal routing.
<parameter> : Any additional parameters will be passed to the getSkinUrl() method.

Usage
{{store direct_url=”images/myimage.gif”}}
Outputs: http://www.mydomain.com/images/myimage.gif

{{store url=”mens”}}
Outputs: http://www.mydomain.com/mens/

Note that the Base URL can be different in a multistore setup.

htmlescape

Parameters
var : The string to be html escaped.
allowed_tags : Tags to be allowed in the escaped string

Usage
{{htmlescape var=”<a href=’#'>Click Here</a>”}}
Outputs: <a href=’#'>Click Here</a>
Note: The string is escaped so that the browser does not interpret it as HTML, instead it’s displayed as a human readable string.

var

Description
Outputs template variables.

Parameters
variable : The variable being requested

Usage
{{var myVariable}
Outputs: Value stored in myVariable

protocol

Description
Outputs the proper protocol (HTTP or HTTPS) depending on current context OR outputs the desired url based on the current protocol.

Parameters
store : The desired store
url : The url to prefix with the proper protocol
http : The url to use if the current protocol is HTTP
https: The url to use if the current protocol is HTTPS

Usage
{{protocol url=”www.mydomain.com/images/checkout/cart.gif”}}
Outputs: http://www.mydomain.com/images/checkout/cart.gif IF current protocol is HTTP
Outputs: https://www.mydomain.com/images/checkout/cart.gif IF current protocol is HTTPS

{{protocol http=”http://unsecure.mydomain.com/images/checkout/cart.gif” https=”https://secure.mydomain.com/images/checkout/cart.gif”}}
Outputs: http://unsecure.mydomain.com/images/checkout/cart.gif IF current protocol is HTTP
Outputs: https://secure.mydomain.com/images/checkout/cart.gif IF current protocol is HTTPS

All of these directives are defined in Mage/Core/Model/Email/Template/Filter.php should you want to explore them further.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Kirtsy
  • Propeller
  • Reddit
  • Slashdot
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati

RSS Feed

2 Comments for Magento CMS Tags (Directives)

Tweets that mention Magento CMS Tags (Directives) - SpinOneSolutions -- Topsy.com | April 28, 2010 at 12:39 am

[...] This post was mentioned on Twitter by Satish Kumar. Satish Kumar said: #magento Magento CMS Tags (Directives) – SpinOneSolutions: {{protocol url=”www.mydomain.com/images/checkout/cart.g… http://bit.ly/bsPNZA [...]

Magento@ScreencastWorld | June 6, 2010 at 8:07 pm

Really useful post, thank you. Bookmarked.

Leave a comment!

«

Find it!

Theme Design by devolux.org