我正在尝试制作一个模块,在"before_body_end"
上插入一些JS跟踪代码。到目前为止,我已经成功地注入了我自己的块与.phtml
模板包含跟踪JS的产品视图与以下代码在我的布局XML:
<catalog_product_view>
<reference name="before_body_end">
<block type="catalog/product_view" name="trackingjs_product" template="company/module/product.phtml"></block>
</reference>
</catalog_product_view>
并确保块类型是catalog/product_view,以便我可以访问产品类并获取诸如当前产品ID之类的信息。我的问题是产品列表页面。我尝试了类似的代码catalog/product_list
,但没有工作。
似乎我必须将其设置为catalog_product_view
才能输出任何东西,但是这样我就无法访问产品集合了。关于如何访问产品集合或如何使其在catalog/product_list
上工作,有什么想法吗?
如果您只需要产品或类别信息,则不需要此类块。core/template是找到只要你有Mage::registry('current_product')和Mage::registry('current_category')检索产品和类别信息。
但如果你喜欢自己的方式,我建议你这样做
<catalog_category_layered>
<reference name="before_body_end">
<block type="catalog/product_list" name="trackingjs_list" template="company/module/list.phtml"></block>
</reference>
</catalog_category_layered>
<catalog_category_default>
<reference name="before_body_end">
<block type="catalog/product_list" name="trackingjs_list" template="company/module/list.phtml"></block>
</reference>
</catalog_category_default>