2

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?

2 Answers 2

3

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.

4
  • Thanks for clarifying Ben, i'll delete my answer if FROSIT can un-accept and mark yours as the accepted answer?
    – JoshCarter
    Nov 10, 2015 at 10:12
  • Up to you @JoshCarter. It's an obscure detail for sure.
    – benmarks
    Nov 10, 2015 at 10:12
  • Hmm, true @benmarks, just thinking for the benefit of any future exam takers looking for help.
    – JoshCarter
    Nov 10, 2015 at 10:14
  • 3
    Hi benmarks, thanks for correcting this. Because there's like almost none documentation about this i think it's important people taking the exam should now about this. Today i got these questions again and the options without block= didn't make any sense. I just tested this and it can be used by for example method="setTemplate" block="my_block". I passed eventually with a score to be proud of :) thanks Stackers!
    – FROSIT
    Nov 10, 2015 at 17:20
2

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

3
  • Thanks for confirming and the examples. Magento did a great job at tricking me the last time haha. When seeing so much bad examples at the exam you get confused with what was bad code and not. I hope i'll pass :)
    – FROSIT
    Nov 9, 2015 at 23:16
  • No worries, good luck again!
    – JoshCarter
    Nov 10, 2015 at 0:58
  • 1
    This is incorrect.
    – benmarks
    Nov 10, 2015 at 10:05

Your Answer

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

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