Question

A couple of weeks ago I failed my frontend developer exam by 1 point, Tomorrow I am going to retake.

I have a question which I want to be sure about. In the exam I had some xml snippets and I had to pick the right one. A lot of times I saw snippets containing block="block_name". I never saw this in any layout xml file ever so I thought this is bad code maybe to trick me. This kind of snippet containing block= popped up several times which started to confuse me.

I searched everywhere but couldn't find an example. Do you guys now any usage for this or is it to trick me?

Example

<action method="insert" block="contactForm"/>

Can someone clarify this? Can block= be used in some xml code or not?

Was it helpful?

Solution

Although it is never used in core layout XML, the block parameter of action entities is a shorthand which is perfectly valid and allows you to use actions outside of a reference or block scope. For example:

<default>
    <reference name="contactForm">
        <action method="someMethod"><params /></action>
    </reference>
</default>

has the same effect as:

<default>
    <action method="someMethod" block="contactForm"><params /></action>
</default>

Note that I said "has the same effect as" rather than "is the same as"; I believe there may be an ordering difference between the two. Would have to check to confirm.

OTHER TIPS

I believe that there is no usage for block= in Magentos xml, action, template, name, type, method, as, before and after are a few of the main usages for Magento. There is no need for a block= as you are defining the block type in the type="" value.

Also when using the above method to insert a block you would use the following syntax, notice how block has its own node:

<action method="insert">
     <block>contactForm</block>
</action>

Insert can also only be used to insert a block tha thas previously been unset eg. before the above example you would have:

<action method="unsetChild">
     <name>contactForm</name>
</action>

Hope this helps, and good luck on your exam!

Josh

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top