2

How do I insert a custom block right above the coupon code field in the shopping cart by just using the layout.xml (without editing the template using getChildHtml()).

I had done it before now i just cant seem to remember the block name..

2

2 Answers 2

2

Add the following code in your themes local.xml and check.

<checkout_cart_index translate="label">
<reference name="checkout.cart">
<block type="core/template" before="coupon" name="sample" template="sample.phtml"/>
</reference>
</checkout_cart_index>
1
  • this doesnt place above the "discount coupon" box
    – anant
    Sep 30, 2016 at 12:36
0

Magento provides a placeholder for extensions or custom blocks that you can use which is called checkout.cart.extra as you can see from the cart.phtml template:

<div class="col-2">
    <?php /* Extensions placeholder */ ?>
    <?php echo $this->getChildHtml('checkout.cart.extra') ?>
    <?php echo $this->getChildHtml('coupon') ?>
    <?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
</div>

So you can totally do the following in your local.xml file:

<checkout_cart_index>
    <reference name="checkout.cart">
        <block type="core/text_list" name="checkout.cart.extra" translate="label">
            <label>Checkout Forms Extra</label>
            <block type="core/template" name="my.custom.block" template="path/to/template.phtml"/>
        </block>
    </reference>
</checkout_cart_index>
6
  • i would like to do it without hardcoding into templates, I know there is wa way, i just forgot the block name
    – anant
    Sep 30, 2016 at 12:37
  • @anant well read my solution again. The template code is from the core you don't have to exit the template simply use the layout code I pasted Sep 30, 2016 at 12:50
  • but it is not inserting the block right above the discount block
    – anant
    Oct 4, 2016 at 13:53
  • how to add block in admin order create page ? layout xml @RaphaelatDigitalPianism Nov 5, 2016 at 6:15
  • @lalitmohan that's a totally different question please create a new question Nov 5, 2016 at 7:11

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.