hann...
hann...

Reputation: 70

Magento different examples for inserting an existing block

I would like to understand the difference in the example codes I've found in different resources to insert a block though the Magento local.xml file.

<action method="insert"><name>catalog.compare.sidebar</name></action>

<action method="insert"><block>catalog.compare.sidebar</block></action>

<action method="insert"><blockName>catalog.compare.sidebar</blockName></action>

The action method is the same for each approach, but the name of the parameter difference. Each example seems to work fine, so what is the difference between using "name", "block" or "blockName" in this context?

Thanks in advance.

Upvotes: 0

Views: 281

Answers (1)

Jona
Jona

Reputation: 1156

By this way, you basically tell to Magento to call the method "insert" of the block specified by the parent node of your action node. (Or in app/code/core/Mage/Core/Block/Abstract.php)

Magento don't take care about te name of the children nodes but only their value.

You can watch in app/code/core/Mage/Core/Model/Layout.php

public function generateBlocks($parent=null)
{
        if (empty($parent)) {
            $parent = $this->getNode();
        }
        foreach ($parent as $node) {
            $attributes = $node->attributes();
            if ((bool)$attributes->ignore) {
                continue;
            }
            switch ($node->getName()) {
                case 'block':
                    $this->_generateBlock($node, $parent);
                    $this->generateBlocks($node);
                    break;

                case 'reference':
                    $this->generateBlocks($node);
                    break;

                case 'action':
                    // WE GO HERE WHEN WE HAVE AN ACTION NODE
                    $this->_generateAction($node, $parent); 
                    break;
            }
        }
}

Then when you look at _generateAction(), i'll not paste all the method:

.... 

$args = (array)$node->children();

....

call_user_func_array(array($block, $method), $args);

So, whathever the argument tagName is, the result will be the same.

Cheers,

Upvotes: 1

Related Questions