Magento CMS syntax – part1

Featured Image

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 ..

EDIT: Magento CMS syntax – part2

20
Top

Care to rate this post?

Author

Ivan Weiler

Technical Educator and Consultant

Ivan is a Technical Educator and Consultant. He gained lots of experience managing some of the most complex Magento projects we had at Inchoo.

Other posts from this author

Discussion 20 Comments

Add Comment
  1. really gud one

  2. Jacob

    Nice overview. I’ve published a less technical article about this syntax on the Magento wiki: http://www.magentocommerce.com/wiki/markup_tags

    I’ll update the article with a link to this one.

  3. That’s great man, Thx. Wiki page is great, don’t know how I missed it before !!

    Hopefully, we’ll provide enough info and examples for other Magento users.

  4. Great article!! What about e-mail template syntax?

  5. OOHH! Great article! I’ve been looking for something like this for a long time. Thank you!

  6. Lee Saferite

    @David: the email template syntax is exactly the same as the CMS template syntax because the CMS actually uses the email template filter to work. With email you just need to know what variables are available.

  7. ha ha!i am looking for this!

  8. I was looking for this today and didn’t see it in this totorial… maybe someone can use it…

    GET BASE URL IN PHP CODE (not in CMS):

    <a href="getUrl(”); ?>help” class=”link-cart”>__(‘Help’); ?>

  9. Mona

    Nice article but you know what you can use Varien_Filter_Template class directives cuz if you can’t you won’t use depend for example but there is a special syntax for everything and you can find the pattern specified in constants in that class ;)

    cheers

  10. @Mona: how can if/depend/include/etc directives be used in cms, if i’m not mistaken, they can’t be used ?? or did i missed something ;)

  11. Emilia

    Hello, I’m looking for some help… You said the email template syntax is the same as the CMS… oh-oh. I’m not receiving any test emails (transactional, new password, etc.) with variables with dots “.” and equal signs “=” (like {{var subscriber.getConfirmationLink()}}). I tried single and double quotes, underbar and “()” and they’re ok. And I’m using tags with dots and equal signs in CMS pages… Checked encoding, templates, locale… what am I missing?

  12. ABU

    How i add custom block type…that is how i add
    <block type="custom/html_banner"

  13. Thank you for this. Do you know if this stuff is in any of the Magento books? I know they’re all outdated already, but I find there’s limited magento help in most cases.

  14. COBAY

    Hi, all ~

    filter() method in Mage_Core_Model_Email_Template_Filter class

    the filter() method is very useful.
    for example, it is used as below.

    $obj = Mage::getModel(‘core/email_template_filter’);
    echo $obj->filter(‘
    KIM

    ‘);

    OUTPUT is returned to real image path. ^^

  15. Very helpful information for any Magento webmaster, thanks!

  16. Martin

    Nice post thanks. Does anyone know how to access a product attribute using the var syntax ie {{var product.attribute}}

  17. Thanks for this article,

    maybe you can answer this question:

    Is it possible to use language independent magento url tags?

    e.g something like this: test

    but with an output of an speaking url like
    http://www.my-domain.de/my-en-category

  18. edit:
    oops, test link above is build like this:
    a href = {{store url=’catalog/category/view/id/10′}}

  19. Thanks for this great article.Hope will get more magento article like this in future.

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top