5

I am trying to insert my core template file in product view page before price using layout xml.

I've tried this.

<catalog_product_view>
    <reference name="content">
        <block type="core/template" name="myblock" as="myblock" template="mymodule/mytemplate.phtml"/>
    </reference>
</catalog_product_view>

But it displays at the bottom of the content just before footer.

And then I try to add before="product.info.simple"

<catalog_product_view>
    <reference name="content">
        <block type="core/template" name="myblock" as="myblock" template="mymodule/mytemplate.phtml" before="product.info.simple"/>
    </reference>
</catalog_product_view>

But it displays above the content just after breadcrumb.

So, anybody know how to make it displays just before the price?

0

3 Answers 3

7

The problem is you can add a block only to another block which has core/text_list type. So you need to find a closest block of such type to a place where you want to position your block.

If you want to make it for simple products only (which follows out of your question) you can do something like this:

<?xml version="1.0"?>
<layout>
    <PRODUCT_TYPE_simple>
        <reference name="product.info.simple.extra">
            <block type="core/template" name="test" template="test.phtml" before="-"/>
        </reference>
    </PRODUCT_TYPE_simple>
</layout>

for all types of products this is the closest you can get:

<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="alert.urls">
            <block type="core/template" name="test" template="test.phtml" after="-"/>
        </reference>
    </catalog_product_view>
</layout>
1
  • It should be noted that core/text_list-like behavior is seen in in template blocks when getChildHtml('') is called with empty string as first param. If the third param is passed as true it will even render children blocks by sort, just like core/text_list behavior.
    – benmarks
    Commented Mar 2, 2013 at 2:01
6

The alternative is to change the catalog/product/view template and add a

$this->getChildHtml('my_cool_block_name');

and add it to the local.xml

<catalog_product_view>
    <reference name="product.info">
        <block type="core/template" name="my_cool_block_name" template="test.phtml" after="-"/>
    </reference>
</catalog_product_view>
0
0
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('mymodule/mytemplate.phtml')->toHtml(); ?>

you are anywhere using this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.