0

Trying to insert custom template/block into specific place in => product.info.addto

for some reason my block appears either before or after and I can't manage to insert it anywhere else.

<?xml version="1.0" encoding="UTF-8"?>
<layout>
<catalog_product_view>

    <reference name="content">

        <block type="amber_custom/catalog_product_custom" name="linked.product" template="amber/catalog/product/custom.phtml" after="product.reviews"/> <!-- trying inset it after this block but no luck -->

    </reference>

</catalog_product_view>
</layout>

What is the problem, why it won't go there ?

To find out all the block names i'm using "ath" - advanced theme hint , it shows all the names correctly.

  • add alias in before or after. Find alias from your catalog.xml and local.xml – Gopal Patel Feb 27 '17 at 17:38
2

Changes

  1. Copy catalog/product/view.phtml into to your theme if it isn't already (never directly edit core files or you could lose your changes)
  2. Inside this template add <?php echo $this->getChildHtml('linked.product') ?> to where you want it to render
  3. In your layout XML change <reference name="content"> to <reference name="product.info">

Explanation

The problem arises because you're using <reference name="content"> - content is a structural block and structural blocks will automatically render child blocks and this is your problem as it can be difficult to position blocks this way.

Why before/after isn't working for you

after isn't working for you because your block is using the reference content whilst product.reviews inside the reference of product.info.

You're best bet is to use <reference name="product.info"> rather than content and then copy over catalog/product/view.phtml into your theme if it isn't already (never edit the core or Ben Marks will hunt you down).

Now inside this template add the following:

<?php echo $this->getChildHtml('linked.product') ?>

This will render your block where ever you add that line of code.

At first the above seems a bit strange and not so straight forward, but after you've done it a few times it becomes second nature and actually makes sense.

  • Thank you Ben, it really works ;) It seems to be a really good method, I did exactly what you suggested and surprisingly the effect was positive. However, this is a pretty good trick, unfortunately if I would like to create a module fully transferable it will not work. How can I do it or what I suppose to change to make it work ? I'm a quiet new in Magento and many things is a complete mystery for me :) – Rob D. A. Feb 27 '17 at 21:33

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.