覆盖Magento块和模板
我正在尝试用模块中提供的新模板覆盖Mage_Catalog_Block_Product_Price_Template块和模板,通过设置配置覆盖该块是可以的:覆盖Magento块和模板,magento,Magento,我正在尝试用模块中提供的新模板覆盖Mage_Catalog_Block_Product_Price_Template块和模板,通过设置配置覆盖该块是可以的: <global> <blocks> <catalog> <rewrite> <product_price>ABC_PriceX_Block_Price</product_price>
<global>
<blocks>
<catalog>
<rewrite>
<product_price>ABC_PriceX_Block_Price</product_price>
</rewrite>
</catalog>
</blocks>
</global>
并且不呈现模板:
<p>
<?php Mage::log('I am in ABC template'); ?>
</p>
我在这里遗漏了什么吗?您没有提到Magento版本,但是在Magento 1.7.0.1的普通安装中,
Mage\u Catalog\u Block\u Product\u Price\u Template
类,尽管名称有误导性,不是一个模板块类
#File: app/code/core/Mage/Catalog/Block/Product/Price/Template.php
class Mage_Catalog_Block_Product_Price_Template extends Mage_Core_Block_Abstract
{
...
}
请注意,它从Mage\u Core\u Block\u Abstract
扩展而不是Mage\u Core\u Block\u Template
所以,因为它是一个块,所以可以设置一个模板
$this->setTemplate('pricex/price.phtml');
但这只是块的魔法get
和set
方法的作用。类似地,当您调用getTemplateFile
Magento时,会返回null,因为在您的块上还没有人调用setTemplateFile
。(与从Mage\u Core\u block\u Template
继承的块相反,该块实际上有一个已定义的getTemplateFile
方法
您的主要问题是将Mage\u Catalog\u Block\u Product\u Price\u Template
视为模板块,而不是模板块。这由同一块的布局更新XML代码备份
<block type="catalog/product_price_template" name="catalog_product_price_template" />
请注意,扩展Mage_Core_Block_模板而不是Mage_Catalog_Block_Product_Price_模板显示了旧的价格模板“frontend\base\default\Template\Catalog/Product/Price.phtml”和新的Block ABC_PriceX_Block_价格,这甚至比模板/非模板块更奇怪?magento网站上提到的所有内容都是结构化和结构化的内容块模板块是一个使用phtml
模板来呈现其内容的块。非模板块是一个使用其HTML方法来呈现模板的块,并且由于其他原因被插入到布局中。答案很好-总是想知道为什么我不能grep price.phtml!
$this->setTemplate('pricex/price.phtml');
<block type="catalog/product_price_template" name="catalog_product_price_template" />