0

When Magento calls:

{{layout handle="sales_email_order_items" order=$order}}

inside an email template, is the 'order=$order' bit simply an argument pair? Is it passing the entire $order object along to the phtml template file as $this->getOrder()?

I know I knew the answer to this at one point but have since forgot. =(

1 Answer 1

0

That depends entirely on the implementation of the particular directive. In you example, the layout directive is handled in

#File: app/code/core/Mage/Core/Model/Email/Template/Filter.php
public function layoutDirective($construction)
{
    ...
}

The $construction parameter contains a list of the template tag's attributes. These are parsed out into paramaters

$params = $this->_getIncludeParameters($construction[2]);

a new layout object is instantiated

$layout = Mage::getModel('core/layout');

and then for each block in the new layout object, each param is assigned as a data parameter

foreach ($layout->getAllBlocks() as $blockName => $block) {
    /* @var $block Mage_Core_Block_Abstract */
    foreach ($params as $k => $v) {
        if (in_array($k, $skipParams)) {
            continue;
        }

        $block->setDataUsingMethod($k, $v);
    }
}

The above assumes Magento 1.7.x.

3
  • So when it passes order=$order to a phtml template, is that object all ready to go in the phtml template? Or is that dependent on the block type defined in the layout.xml file? How is $object called?
    – pspahn
    Sep 20, 2012 at 22:07
  • Probably quicker to just try it than for me to take a guess. Sep 20, 2012 at 23:34
  • 1
    Not sure why it wasn't working when I tried initially, but it's as simple as $this->getOrder() to grab the order=$order object passed via the layout directive.
    – pspahn
    Sep 21, 2012 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.