3

I'm trying to add a small form to the category view to each product by using the <catalog_category_view> layout handle. The block of my module already works on product detail pages (<catalog_product_view> in product.info block).

Is there some requirement for the product_list block to accept another child block which I'm calling explicitly by name within the catalog/product/list.phtml? My form block class extends the basic Mage_Core_Block_Template if it makes any difference.

edit: added source

<!-- working -->
<catalog_product_view>
    <reference name="product.info">
        <block type="annotations/form" template="productannotations/form.phtml" name="product_annotations" />
    </reference>
</catalog_product_view>

<!-- not working -->
<catalog_category_view>
    <reference name="product_list">
        <block type="annotations/form" template="productannotations/form.phtml" name="product_annotations" />
    </reference>
</catalog_category_view>

embeding the block directly via echo $this->getLayout()->createBlock('annotations/form', 'product_annotations')->setTemplate('productannotations/form.phtml')->toHtml() works on the other hand.

  • Can you post the code you have so far? – Marius Mar 18 '15 at 11:29
  • @Marius added my layout.xml code. Also I changed the extending class from Mage_Core_Block_Template to Mage_Catalog_Block_Product_Abstract – Pascal Heidmann Mar 18 '15 at 14:35
1

you can add new block like below.

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
      <block type="core/template" name="product_custom_form" template="path/to/phtml"/>
</block>

In Listing file add code in foreach of product collection like below:

<?php foreach ($_productCollection as $_product): ?>
<form name="producid-form" action="yoururl">
    <?php echo $this->getChildHtml('product_custom_form'); ?>
</form>

Note: add only input fields in you form phtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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