2

In my project, I have many layout handles which I am calling on different MVC actions (mostly on click). I just realized that the layout handles have a common code between them something like this:

<block name="reports.product.viewed" type="a/b_c" template="a/c.phtml"></block>
<block name="catalog.product.new" type="b/b_c" template="b/c.phtml"></block>
<block name="customer.allreviews" type="c/b_c" template="c/c.phtml"></block>
<block name="best.sellers" type="d/b_c" template="d/c.phtml"></block>

So, I planned to move the above code in a layout handle common_code_lines and call the layout handle instead of writing the above four lines. i.e

<reference name="content">
    <!-- other blocks -->
    <update handle="common_code_lines"/>
</reference>

This is just not working.. no errors.

What I am missing? please help.

2 Answers 2

1

You still need to reference the parent block inside the handle, this means, layout handles are not replaced by the code. Instead they are processed too.

Instead of doing this, which is not possible...

<block name="reports.product.viewed" type="a/b_c" template="a/c.phtml"></block>
<block name="catalog.product.new" type="b/b_c" template="b/c.phtml"></block>
<block name="customer.allreviews" type="c/b_c" template="c/c.phtml"></block>
<block name="best.sellers" type="d/b_c" template="d/c.phtml"></block>

<reference name="content">
    <!-- other blocks -->
    <update handle="common_code_lines"/>
</reference>

You can do this:

<reference name="content">
    <block name="reports.product.viewed" type="a/b_c" template="a/c.phtml"></block>
    <block name="catalog.product.new" type="b/b_c" template="b/c.phtml"></block>
    <block name="customer.allreviews" type="c/b_c" template="c/c.phtml"></block>
    <block name="best.sellers" type="d/b_c" template="d/c.phtml"></block>
</reference>

And inside the other handle's root:

<update handle="common_code_lines"/>
1
  • Sorry, I didn't get you..
    – Mr_Green
    Feb 21, 2014 at 10:55
1

Assume you want to call common_code_lines handler inside the sample_text_testhandler.

Then your code should be like this. Put <update ... /> node just after the handler sample_text_test.

E.g.

<sample_text_test>
    <update handle="common_code_lines"/>
    <reference name="content">
        <!-- other blocks ..>
    </reference>
</sample_text_test>

Note: The node means, Take the layout update handle and merge it’s contents with the current layout xml.

Your Answer

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

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