2

I have a magento installation where I need to place related products in the center column. This is the easy part. I moved

<block type="catalog/product_list_related" name="catalog.product.related" after="container1" template="catalog/product/list/related.phtml"/>

From the right reference block, to the bottom of the center reference block.

With this I achieved to place the related products in the center column, but all the way at the bottom.

I need the related products to be placed just above the price block in the div (class: product-shop)

I tried to position it with the After/before parameter in the XML but this doesnt seem to work.

If I place the block code higher up in the XML it doesn't show at all.

Charles
  • 50,943
  • 13
  • 104
  • 142
Martin-bt
  • 98
  • 3
  • 9

1 Answers1

10

Moving blocks is quite easy to do correctly (i.e. using best practices). Best practices include not customizing any core layout file when possible as well as working with original block instances rather than reinstantiating them. All of this can be achieve using the custom layout file available to end-implementers.

Create a local.xml file in your custom theme's layout folder e.g. app/design/frontend/[package]/[theme]/layout/local.xml, and in there add the following:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <!--
        In Magento v1 a move is accomplished by unsetting in one place
        and inserting in another. This is possible using just layout xml
        when the "new" parent block is a "Mage_Core_Block_Text_List"
        instance. Otherwise a template needs editing.

        In Magento v2 there will be actual "move" functionality.
    -->
    <catalog_product_view>
        <reference name="right">
            <!-- remove the block name from a parent -->
            <action method="unsetChild">
                <block>catalog.product.related</block>
            </action>
        </reference>
        <reference name="content">
            <!-- add the block name to a parent -->
            <action method="insert">
                <block>catalog.product.related</block>
            </action>
            <!--
                Mage_Core_Block_Abstract::insert() accepts multiple arguments,
                but by default it will insert the added block at the beginning
                of the list of child blocks.
            -->
        </reference>
    </catalog_product_view>
</layout>

You can revert the change to the original layout xml file at this point.

benmarks
  • 23,384
  • 1
  • 62
  • 84
  • Hi Benmarks, thanks for your answer. You are definitely right. I need to use local.xml instead of modifying the xml files. Thanks for sharing how to do it. But it doesnt help on the problem how I place the related products up with the price instead of in the bottom of the product page. (It wont show anywhere but in the bottom) – Martin-bt Jan 01 '13 at 13:52
  • Sorry, I had an error in my script (missing layout update handle `catalog_product_view`). The directives from *local.xml* are evaluated **after** the directives from `catalog.xml`, so the block should be inserted at the beginning of the list of children in the content area. Also, note that there may be some JS/DOM assumptions (the related tickboxes update a field in the middle form); test that the form works in the content area. – benmarks Jan 01 '13 at 14:01
  • Thanks Benmarks, Its the day after new year, maybe Im a bit slow today :) It helped me so far that the related products box is now showing in top of the product view page (and with the correct way to do it). But I need it in the middle of the elements. I have: Product name Product short desc - Product price and buy button - And here I want the Related products - Product long desc - Do you follow me? – Martin-bt Jan 01 '13 at 14:14
  • Ah, in that case, you need to `insert()` to (probably) the `product.info` block rather than the `content` block, and you will need to customize the template. – benmarks Jan 01 '13 at 14:16
  • Thanks Benmarks, I think you helped me far enough, I need to play a bit more arround with the insert() to fully understand it. Because as far as I can see the content block is a reference, and the product.info is a block. But I really appreciated your help. Thanks for pointing me in the right direction. – Martin-bt Jan 01 '13 at 14:24
  • FYI `` refers to a block. See [*app/design/frontend/base/default/layout/page.xml* (link)](https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/design/frontend/base/default/layout/page.xml#L91) – benmarks Jan 01 '13 at 14:26
  • Ahhh that was a good information. I actually thinks I understand it a bit more now. Thans so much. Its my first time here on stackoverflow asking questions, but definitely not the last time. Should I do more than giving you a green checkmark to finish this subject? – Martin-bt Jan 01 '13 at 14:30
  • Nope, just mark the answer which is best. Other than than, you might consider [following the proposal for a dedicated Magento site here at StackExchange](http://area51.stackexchange.com/proposals/48872/magento?referrer=HFqQT3Qeb2X27y6ehRWkiw2) - if you do follow, vote up questions which have been asked and ask your own as well if you like. Welcome to the party! – benmarks Jan 01 '13 at 14:48
  • In Magento 2 `` instruction was introduced. Hope it will be released soon and all this magic with `Mage_Core_Block_Abstract::insert()` will be forgotten. – Dmytro Zavalkin Jan 01 '13 at 22:36