Magento’s layout and template system is where the framework truly shines and demonstrates the true beauty of its modular nature. One of the most powerful pieces of functionality with layout files is the action handle. I’ll give you a brief overview of how action handlers work and provide you with a reference list of action methods that come pre-packed with Magento’s core.
What does the Magento action layout handle do?
The action handle is used to control client-facing functionality. An action handle must be a child of a or handle. Presence of an action handle in your layout tells Magento that you want to call a block function referenced in the action’s method property.
How does Magento know which block your action method is in?
Magento will look at the type of the parent or referenced block, and will attempt to call the action method in there.
How do you pass parameters into a Magento action method?
If the block function you are reference takes parameters, you can specify child nodes in your action. The names of the nodes is not important, but should be named something meaningful. The value inside these nodes is what is important, as they are the values that Magento will pass into the function that it calls.
Can I call my own block functions using the layout.xml action handle?
Yes. All the action parameter does is look at the parent block or reference and try to call the function you specify inside the method="" property. If the action handle has child nodes, their values will be passed to the function as parameters.
Example of Magento Layout XML Action Method Usage
To better grasp the concepts that I am talking, let us consider the following example of some XML that could be placed in your themes local.xml:
<!-- Found in: /app/design/frontend/base/default/layout/page.xml -->
<block type="page/html_head" name="head" as="head">...</block>
I mentioned that Action methods must be a child of or nodes. Note that in this example, I am referencing a block with an alias of head.
If you look at the declaration for the head block, you will notice that its type is “page/html_head”. This is the block that Magento will try to call your action method in. To take this a little further, Magento will look for the following block:
The action method we have described is addJs. You may have noticed that the action handle also has a child handle. This means that when Magento tries to call addJs(), it will pass in the child of the action a parameter.
Ultimately magento will call addJs(‘customScript.js’);