Search code examples
magentomagento-1.5

action method on block does nothing


I've got the following block definition, which outputs the block of "my/type" just fine:

<block type="my/type" template="my/template.phtml">
  <action method="setMyFlag"><value>MyValue</value></action>
</block>

There's only one problem: setMyFlag is not invoked. I've used this approach before succesfully on other custom blocks, but for some unbeknown reason, I cannot get it to work.

I'm actually relying on the magic setters, but I've also just added the setMyFlag method to My_Type and put a breakpoint in it. All to no avail.

Any clues as to what might go wrong here?


Solution

  • After some debugging, it seems that having a name is prerequisite for blocks to be able to invoke methods on it. So just adding a name fixes my issue:

    <block type="my/type" template="my/template.phtml" name="my_name">
      <action method="setMyFlag"><value>MyValue</value></action>
    </block>