Question

I'm currently making my own module, but i'm having trouble with just displaying a block in the catalog product view.

I've added this line to default/layout/catalog.xml

<block type="catalog/product_view" name="product.info.rating" template="rating/rating.phtml"/>

and my template/rating/rating.phtml looks like this

<p>halp</p>
Was it helpful?

Solution

Add this in your your_theme_path/layout/local.xml instead.

<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
   <reference name="product.info">
       <block type="catalog/product_view" name="product.info.rating" template="rating/rating.phtml"/>
   </reference>
</catalog_product_view>
</layout>

Now call child html in theme/template/catalog/product/view.phtml

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

Another way

If you don't want to edit theme/template/catalog/product/view.phtml file then change your local.xml as follow:

<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
   <reference name="alert.urls">
       <block type="catalog/product_view" name="product.info.rating" template="rating/rating.phtml"/>
   </reference>
</catalog_product_view>
</layout>

This block will appear automatically in product view page, however it will be called along with other alert.urls

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top