2

In my project, I am trying to shift positions of two templates in home page of "modern" theme by updating layout in local.xml file. The template file names are as follows:

1)  frontend\base\default\template\page/switch/languages.phtml

2)  frontend\base\default\template\page/template/links.phtml

The above template files are referencing the below block names in layout folder of "base/default".

1)  store_language

2)  top.links

Both blocks are in same parent block which is "header". So, I wrote the local.xml like this in "default/modern/layout" folder.

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="header">     
            <remove name="top.links"/>
            <block type="page/template_links" name="top.linked" as="topLinked" template="page/template/links.phtml" before="store_language"/>
        </reference>
    </default>
</layout>

The above update layout has removed the block "top.links" successfully but not adding the new block "top.linked" again before the "store_language" block. what I am doing wrong here?

For better understanding, please refer the below screenshot.

enter image description here

I have also some other questions like:

  • Does updating of a layout should be done using "local.xml" file only?
1
  • <reference /> and <remove /> should both be directly inside the layout update handle (e.g. <default />).
    – benmarks
    Sep 9, 2013 at 13:09

2 Answers 2

2

<remove .. /> directive removes block completely. Even if you are adding it afterwards with the same name it will be still removed.

If you want to remove block from one place and insert it into another you have to do instead is to unsetChild first and insert it wherever you want.

However this will not help in your case. Those two blocks are echoed inside of header.phtml explicitly so it would be much easier just to switch their places there.

2
  • Can you please show me an example of how to do it? or just a link would be enough.. :)
    – Mr_Green
    Sep 8, 2013 at 15:50
  • You can try to play with adding one block inside of the other.
    – user487772
    Sep 8, 2013 at 15:55
2

if you check the file template/page/html/header.phtml you'll notice that all blocks are called using the getChildHtml function. This means that, in order to get your topLinked block you'll have to add some code in the header.phtml file.

[...]
<div class="quick-access">
    <?php echo $this->getChildHtml('topSearch') ?>
    <p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
    <?php echo $this->getChildHtml('topLinked') ?>
    <?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
[...]

On line 5 I've added your topLinked block. This will include the block before store_language in the header.

Still removing the old top.links and adding a new one won't be required. Just move the getChildHtml calls around in the header.phtml and you can position them however you want.

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.