0

i'm creating a menu in this way:

<block type="page/template_links" name="footer_links2" as="footer_links2" template="page/template/links.phtml">
    <action method="setTitle"><title>Main menu</title></action>
    <action method="addLink" translate="label title" module="catalogsearch">
        <label>About us</label>
        <url helper="cms/page/getPageUrl"><pageId>3</pageId></url>
        <title>About us</title>
    </action>
    <action method="addLink" translate="label title" module="catalogsearch">
        <label>Contact us</label>
        <url helper="cms/page/getPageUrl"><pageId>4</pageId></url>
        <title>Contact us</title>
    </action>
    <!-- Other links here... -->
</block>

and it works, but i want that the same menu appears in a different part of the page too with the same content. Is there a way to duplicate the output of that block so that i can show it without duplicating the code?

2
  • what do u mean without duplicating the code? you can use the same block in other references as well. – MTM Aug 23 '14 at 8:31
  • Is there are a way to use the same block without rewriting its entire definition? How? – mck89 Aug 25 '14 at 7:06
1

Through layout XML, you will have to repeat the block calling for each reference. like if you want to call the same block in header, you will have to do following:

<reference name="header">
 <block type="page/template_links" name="footer_links2" as="footer_links2" template="page/template/links.phtml">
    <action method="setTitle"><title>Main menu</title></action>
    <action method="addLink" translate="label title" module="catalogsearch">
        <label>About us</label>
        <url helper="cms/page/getPageUrl"><pageId>3</pageId></url>
        <title>About us</title>
    </action>
    <action method="addLink" translate="label title" module="catalogsearch">
        <label>Contact us</label>
        <url helper="cms/page/getPageUrl"><pageId>4</pageId></url>
        <title>Contact us</title>
    </action>
    <!-- Other links here... -->
  </block>
</reference>

and then call this block by $this->getChildHtml('footer_links2'); method. you will have to repeat it for any other reference.
but if you don't want to repeat these steps, you can create a static block, enter the links in it and then call that static block anywhere you want it to. So one change will update the links wherever this static block is shown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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