Magento separate price.phtml

Magento separate price.phtml

September 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento separate price.phtml

Customizing Price Templates in Magento: A Practical Guide

When working with Magento, you might find yourself needing to customize the price display for different product views. The default theme uses a single price.phtml template across both category listing and individual product pages. However, there are scenarios where you may want to apply separate styles or calculations to the prices shown in these contexts.

Let’s dive into how you can achieve this by creating a new price template specifically for the category view page.

Understanding Magento’s Price Rendering System

Magento uses block classes to render prices in its templates. The Mage_Catalog_Block_Product_List class, which is responsible for rendering products on the category listing page (template/catalog/product/list.phtml), calls the getPriceRendered() method of each product object.

By default, this method returns the price rendered using the core price template (catalog/product/price.phtml). However, we can override this behavior to use a custom template for our needs.

Creating a Custom Price Block

To begin, let’s create a new block class that will extend Mage_Catalog_Block_Product_List and override the price rendering logic:

require_once 'Mage/Catalog/Block/Product/List.php';

class MyCompany_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_List {

    protected function _getProductPriceHtml($product, $priceTypeCode = null) {
        // Load your custom template file here
        return $this->renderView($this->_template, 'catalog/product/price_custom.phtml', array('product' => $product));
    }
}

In this code snippet, we override the _getProductPriceHtml() method and load a new price template (catalog/product/price_custom.phtml) instead of the default one.

Defining Your Custom Price Template

Now that you have your custom block class set up, let’s create the corresponding price template file. Create a new price_custom.phtml file in the following directory:

app/design/frontend/[your_package]/[your_theme]/template/catalog/product/

In this template, you can apply any desired styling or price rendering logic specific to your category view page. For example, you might want to display prices in a different font weight for better contrast.

Applying the Custom Block

To ensure that Magento uses our new block class instead of the default one, we need to update the layout XML files. Open app/design/frontend/[your_package]/[your_theme]/layout/catalog.xml and add the following code:

<catalog_category_layered>
    <reference name="product_list">
        <action method="setTemplate"><template>catalog/product/list.phtml</template></action>
    </reference>
    <reference name="product_list">
        <action method="setType"><type>custom_type</type></action>
    </reference>
    <reference name="product_list">
        <block type="mycompany_catalog/block_product_list" template="catalog/product/list.phtml"/>
    </reference>
</catalog_category_layered>

In this layout update, we replace the default product list block with our custom block class (mycompany_catalog/block_product_list).

Conclusion

By following these steps, you can successfully create a separate price template for your category view page without affecting the pricing display on individual product pages. This allows you to apply specific styles or rendering logic tailored to each context.

Remember that when working with Magento’s template system, it’s essential to keep your customizations in a separate theme or package. This approach ensures easier maintenance and upgrade compatibility.

For more advanced customization techniques and best practices in Magento development, consider exploring our comprehensive resources at Laravel Company.

Happy coding!

Catalog Themes Pricing

Our network