Martin-bt
Martin-bt

Reputation: 98

Placement of Related products - Magento

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.

Upvotes: 2

Views: 6550

Answers (1)

benmarks
benmarks

Reputation: 23205

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.

Upvotes: 10

Related Questions