Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento cms page rendering {{ }} variables

Where in magento are the {{ }}-variables beeing exactly replaced? File?

like image 637
timopeschka Avatar asked Dec 09 '22 10:12

timopeschka


1 Answers

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

like image 50
Alan Storm Avatar answered Jan 04 '23 17:01

Alan Storm