Markup Tags of magento CMS

来源:互联网 发布:韩国眼中的中国 知乎 编辑:程序博客网 时间:2024/06/05 00:27

*  Markup Tags
          o What is a template tag?
          o Where can I use template tags?
          o How do I use template tags?
          o Which tags can I use?
                + {{block id='block_id'}}
                + {{block type='module/package_classname' template='path/to/template.phtml'}}
                + {{htmlescape var='' allowed_tags=''}}
                + {{layout handle=''}}
                + {{media url=''}}
                + {{skin url=''}}
                + {{store url=''}}
                + {{store direct_url=''}}
          o How do template tags work?
          o Further information
          o Appendix: Creating a custom block type which can accept arguments


This article details which template tags can be used on CMS pages, in static blocks, and in email templates.

What is a template tag?

 

A template tag is a bit of text surrounded by double curly braces which has a special meaning to Magento, e.g., de>{{store url=""}}de>.

You might use a template tag to

  • link to a page within your store without typing out your domain name
  • embed a block within a page without editing layout or template files

Template tags have a variety of uses.

Where can I use template tags?

 

You can use template tags on CMS pages, in static blocks, and in email templates.

How do I use template tags?

 

You use template tags by entering them in one of the places Magento recognizes them (see above).

To illustrate, say you wanted to display your company’s “About Us” image on your store’s home page. (You can manage the content of the home page by navigating to CMS > Manage Pages and then clicking on “Home page” in the back end.) You might do this by typing

  1. <img src="http://www.example.com/skin/frontend/default/default/images/media/about_us_img.jpg" />

but that’s a lot to type. Instead, using a template tag, you could simply say

  1. <img src="{{skin url='images/media/about_us_img.jpg'}}" />

Which tags can I use?

 

Note: In the following examples I’m assuming that a working Magento install is set up at de>www.example.comde>.

You can use the following tags:

{{block id='block_id'}}

This tag inserts the static block which has the identifier “de>block_idde>“. (Static blocks can be managed by navigating to CMS > Static Blocks in the back end.)

Example:

  1. {{block id='footer_links'}}

This code will insert the “Footer Links” static block.

{{block type='module/package_classname' template='path/to/template.phtml'}}

This inserts a block of the type de>module/package_classnamede> using the template de>path/to/template.phtmlde>. The string de>module/package_classnamede> translates into a class name which is defined in the de>Blockde> directory of de>modulede>. (Thus de>core/text_listde>, for instance, translates intode>Mage_Core_Block_Text_Listde>, which is defined in de>app/code/core/Mage/Core/Block/Text/List.phpde>.)

If the module’s de>Blockde> directory contains no sub directories, the de>package_de> part of the string is omitted. (Thus the string de>tag/popularde> translates into de>Mage_Tag_Block_Popularde>, which is defined in de>app/code/core/Mage/Tag/Block/Popular.phpde>.)

The value of the template attribute should be the path to the template that corresponds to the block, starting from the theme directory (e.g., de>tag/popular.phtmlde>).

Example:

  1. {{block type='core/template' template='cms/custom_page.phtml'}}

This code will cause de>cms/custom_page.phtmlde> to be embedded into the page/email.

{{htmlescape var='' allowed_tags=''}}

Escapes all HTML tags in the value of the de>varde> attribute, except for those specified in the value of thede>allowed_tagsde> attribute. (The latter expects a comma separated list of allowed HTML tags).

Example:

  1. {{htmlescape var='<a href="javascript:alert(1);">Hello</a>'}}

This will produce the output de><a href=”javascript:alert(1);”>Hello</a>de>, i.e., an escaped string which the browser won’t interpret.

{{layout handle=''}}

Inserts HTML layout output. The de>handlede> attribute expects the name of a layout handle, e.g. de>defaultde>.

{{media url=''}}

Inserts the URL of the media directory, e.g., de>http://www.example.com/media/de>. Changing the value of thede>urlde> attribute to a non-empty string will cause the string to be appended to this URL.

Example:

  1. {{media url='catalog/product/l/a/large_phone.jpg'}}

This will produce the output de>http://www.example.com/media/catalog/product/l/a/large_phone.jpgde>.

{{skin url=''}}

Inserts the URL of the current theme’s skin directory, e.g., de>http://www.example.com/skin/frontend/default/default/de>. Changing the value of the de>urlde> attribute to a non-empty string will cause the string to be appended to this URL.

Example:

Assuming you’re using the default theme and the default interface, then

  1. {{skin url='images/media/about_us_img.jpg'}}

will be converted to de>http://www.example.com/skin/frontend/default/default/images/media/about_us_img.jpgde>.

{{store url=''}}

Inserts the store’s base URL, i.e., the URL of the store’s home page. (Sample output: de>http://www.example.com/de>.) Changing the value of the de>urlde> attribute to a non-empty string will cause the string to be appended to the store’s base URL and a slash (de>/de>) to be tacked on to the end of the resulting URL. This trailing slash makes thede>urlde> attribute suitable for referencing directory-like paths, e.g. de>customer/accountde>.

Example:

  1. {{store url='about-magento-demo-store'}}

This will be converted to de>http://www.example.com/index.php/about-magento-demo-store/de>. Note the terminating slash in this URL; this is what distinguishes the de>urlde> attribute from the de>direct_urlde> attribute.

{{store direct_url=''}}

Does the same as de>{{store url=''}}de> but without appending a slash to the resulting URL. This is suitable for referencing file-like paths, e.g. de>coffee/kona-fancy-whole-bean.htmlde>.

How do template tags work?

 

This is roughly what happens when Magento encounters a template tag it understands:

  1. Magento uses the tag to populate an array with three elements. The first element is the whole tag (e.g., de>{{store url='coffee/test.html'}})de>. The second element is the keyword which follows immediately after the opening curly braces (e.g., de>storede>). The third element is the tag’s keyword=value pair (e.g.,de>url='coffee/test.html'de>).
  2. Magento passes the array to a method of the de>Mage_Core_Model_Email_Template_Filterde> class. The name of the method depends on the keyword within the tag: if the keyword is de>storede>, for instance, thede>storeDirectivede> method will be called.
  3. The method returns a value. This value is used instead of the template tag on the front end.

Further information

 

For more on how template tags work and which parameters they take, see Ivan Weiler’s "Magento CMS syntax – part1".

Appendix: Creating a custom block type which can accept arguments

 

To learn how you can use a template tag such as

  1. {{block type='namespace_custom/test' my_param1='value 1' my_param2='value 2'}}

see Moshe’s tutorial on creating a block class which extends Mage_Core_Block_Abstract and overloads the _toHtml() method.


From:http://www.magentocommerce.com/wiki/markup_tags

ref:http://lhdeyx.blog.163.com/blog/static/31819697201001521759600/