开发者

Magento cms page rendering {{ }} variables

Where 开发者_如何学Cin magento are the {{ }}-variables beeing exactly replaced? File?


Those template variables are called template directives. Each one has a different method that's responsible for rendering it. For example, the widget directive

{{widget ...}}

is rendered the the widgetDirective method on the Mage_Widget_Model_Template_Filter class.

class Mage_Widget_Model_Template_Filter extends Mage_Cms_Model_Template_Filter
{
    ...
    public function widgetDirective($construction)
    {
    }
    ...
}

Whereas the var directive

{{var ...}}

is handled by the varDirective method

class Mage_Core_Model_Email_Template_Filter extends Varien_Filter_Template
{
    public function varDirective($construction)
    {
        ...
    }
}   

Each of these in in a different class. It appears whenever Magento wants to add a directive, they extend the old filter class, and add the new directive methods. Then, the class that's used to create the filter object is configurable. There are, as far as I can tell, four different contexts where Magento needs to do a template directive variable replacement.

  1. Catalog Content

  2. CMS Page Content

  3. CMS Static Block Content

  4. Newsletter Content

The filter class alias Magento will use for this are configured at

global/catalog/content/template_filter
global/cms/page/template_filter
global/cms/block/template_filter
global/newsletter/template_filter

Search all your config.xml files for <template_filter/> and you can see which class alias is being used to instantiate the filter object. (You can use ack-grep -i 'template_filter' --xml $MAGENTO or find $MAGENTO -type f -name '*.xml' -exec grep -Hn 'template_filter' {} \; to find all files in the $MAGENTO containing that string).


It looks like Mage_Cms_Block_Page::_toHtml() and Mage_Cms_Block_Block::_toHtml() calls Mage_Cms_Model_Template_Filter::filter(string). This class and the multiple levels of parent classes parse the string through several functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜