limasxgoesto0
limasxgoesto0

Reputation: 4793

Insert new block inside of checkout/cart

My final goal of my plugin project is to let an image be uploaded to the database (done) have it do some functionality (done), and then let it be placed in some arbitrary spot on checkout/cart by the admin (oh the horror).

I’m first just trying to hardcode the .phtml into any block on this page (let’s use “checkout.cart.coupon” for sake of discussion). My xml looks like this:

<checkout_cart_index>
    <reference name="content">
        <block type="embeds/projecttemplates" name="project.offers.embed" template="project/button.phtml" after="checkout.cart.coupon">
        </block>
    </reference>
</checkout_cart_index>

With this, my block just appears at the end of the page. Changing after to before just shifts it all the way to the top. Using a combination of before and after still keeps it at the top of the page. Is there any way to get it to stay where I tell it to without having to resort to Prototype?

Upvotes: 0

Views: 2497

Answers (1)

benmarks
benmarks

Reputation: 23205

If you want a block named "new" to render inside the coupon block, you must do two things as the coupon block uses a template.

Step 1: Make the "new" block a child of the parent block via

<reference name="checkout.cart.coupon" />

or by using

parent="checkout.cart.coupon"

attribute in your block declaration.

Step 2: Customize the coupon template so that it renders your block with:

<?php echo $this->getChildHtml('project.offers.embed') ?>

If you want to get all metaphysically deep and not use a template, you could do the following, which would be sweet:

<checkout_cart_index>
    <reference name="content">
        <block type="core/text_list" name="coupon.and.offers" as="coupon">
            <!--
                This block will displace the existing coupon block by alias,
                but sill leave the coupon block instance in layout so it
                can be added as a child.
            -->
            <action method="insert">
                <block>checkout.cart.coupon</block>
            </action>
            <block type="embeds/projecttemplates" name="project.offers.embed" template="project/button.phtml" after="checkout.cart.coupon" />
        </block>
    </reference>
</checkout_cart_index>

Upvotes: 1

Related Questions