Home » Magento Customization, Magento Guide

Magento CMS syntax – part1

9 October 2009 No Comment

Magento CMS syntax – part1

Every Magento user noticed that there is special {{magentocode}} syntax available in cms pages and blocks. We traced a bit to find out which params are available and what exactly they do.

As strange as this may sound, processor class that gets called is Mage_Core_Model_Email_Template_Filter located at app/code/core/Mage/Core/Model/Email/Template/Filter.php .

There are also some interesting directives in superclass Varien_Filter_Template, but if i’m not mistaken, none of them can be used.

There are six replacement codes  that can be used and each triggers its equivalent Directive function:

skinDirective
mediaDirective
htmlescapeDirective
storeDirective
blockDirective
layoutDirective

I’ll start with easier and most commonly used and continue with advanced ones in part two of this article.

1. skinDirective

Description: Used to retrieve path of skin folder and its files, theme fallback respected
Example: {{skin url=’images/image.jpg’ _theme=’blank’}}
Synonym: Mage::getDesign()->getSkinUrl($params['url'], $params)
Params:
url = empty or relative file path
_theme = alternative theme, fallbacks if file not exist
_package = alternative package
_area = alternative area(frontend,adminhtml)
_type, _default etc. = nothing useful, somebody please correct me if i’m wrong :)

2. mediaDirective

Description: Used to retrieve path of root/media folder and its files
Example: {{media url=’image.jpg’}}
Synonym: Mage::getBaseUrl(’media’) . $params['url']
Params:
url = empty or relative file path

3. htmlescapeDirective

Description: Used to escape special html chars
Example: {{htmlescape var=’<a href=”www.inchoo.net”>inchoo</a><b>inchoo</b><i>inchoo</i>’ allowed_tags=’b’}}
Synonym: Mage::helper(’core’)->htmlEscape($params['var'], $params['allowed_tags'])
Params:
var = string to escape
allowed_tags = comma-separated list of allowed tags

4. storeDirective

Description: Used to build magento routes and custom urls
Example: {{store url=’customer/account’ _query_a=’8′}}
Synonym: Mage::getUrl($params['url'], $params);
Params:
url = magento routers url
direct_url = normal url, appended to baseurl
_query_PARAMNAME = adds query param, for example _query_a=’8′ adds a=8 to url
_fragment = adds fragment, for example #comments
_escape = escapes “,’,<,>
custom = if using magento route url param, every custom param added will be appended like /a/8/b/10

I probably missed something in this last one, but it’s very late and i’m tired of poking through Magento ;)

To be continued ..

By Ivan Weiler from Inchoo.net

Related posts:

  1. Some custom Blocks to help you show products
  2. Run Magento Code Outside of Magento
  3. How to make TinyMCE work with Magento CMS pages
  4. Programatically create Magento blocks and inject them into layout
  5. Magento FLIR

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Security Code: