How to insert core template into product view page before price?
سؤال
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?
المحلول
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>
نصائح أخرى
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>
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('mymodule/mytemplate.phtml')->toHtml(); ?>
you are anywhere using this code.