my .phtml file which lists 3 products in a row is:


This file includes also the following .phtml files to include more information.


I now want to include a custom attribute between these two files price.phtml and price_info.phtml. How can I kind of "hook" into it and include another .phtml file? I know that this works with a XML file - but where/how can I find the correct XML file and how I can include my own .phtml file there?

Would be great if anybody can help me. Thanks


So I am assuming you want to add these to the search results page, but this could work for any other layout handle.

Firstly you will need the layout handle in my assumption catalogsearch_result_index is the value you need.

You then need to find the name of the block that is using the product/list.phtml template. In my assumption it is the name search_result_list.

Now what you can do is using these two items of knowledge and a local.xml file in your theme simply add a new child block.

    <reference name="search_result_list">
         <block type="core/template" name="your-new-name" templte="path/to/your/template" />

Then in your product list template you can call getChild to get this block. You can then set your attribute against it using setData and then call toHtml to get the display.

$_yourBlock = $this->getChild('your-new-name');
$_yourBlock->setData('your_attribute', $product->getData('your_attribute'));
echo $_yourBlock->toHtml();

A slightly "nicer" way would be to use a block type that extends Mage_Catalog_Block_Product and then you can set the product against it and call toHtml. A perfect example of this is the getPriceHtml which takes a product object, sets an template and then calls the toHtml.

public function getPriceHtml($product)
    return $this->toHtml();

One final and maybe simple suggestion is to simply not use a template for the single attribute and include it direct in your theme's product list.

  • Hey David, thanks for this extensive explanation. I am not referring to a search result, when the user clicks on the category in the main menu he will see those three products in one row. How do I find now the right xml explanation like <catalogsearch_result_index><reference name="search_result_list"> to hook in between those two phtml files?
    – Torben
    May 8 '15 at 15:52
  • to find the layout handle you can look at the body class when viewing the source in the browser. This is often the layout handle but with - and not _ May 8 '15 at 15:54
  • I assume you mean: catalog-category-view / In the catalog.xml in my theme folder I can only find <default> and <catalog_category_default translate="label"> so I assume I should create <catalog_category_view> and add the template? But how can I define that it should be between the other two .phtml files mentioned above?
    – Torben
    May 8 '15 at 16:33
  • customize the template so it calls the block in the right place May 8 '15 at 16:34
  • Hey David, do you know a good tutorial that shows how I customize and enhance a template in the right way...?
    – Torben
    May 10 '15 at 20:13

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.