简体   繁体   English

Magento:在view.phtml中包含自定义块

[英]Magento: include custom block in view.phtml

I have created a block accrording to this tutorial: http://www.gravitywell.co.uk/blog/post/how-to-creating-your-own-custom-block-in-magento . 我根据本教程创建了一个块: http//www.gravitywell.co.uk/blog/post/how-to-creating-your-own-custom-block-in-magento Now I need to use my manufacturerblock.phtml on my pruduct view page (just somewhere closed to product description text). 现在我需要在我的产品视图页面上使用我的manufacturerblock.phtml(只是关闭产品描述文本的地方)。

In local.xml (under <reference name="header"> ) I added: (edit: I tried also under <reference name="product.info"> in <catalog_product_view> local.xml (在<reference name="header"> )我添加了:(编辑:我也尝试在<catalog_product_view> <reference name="product.info"> <catalog_product_view>

<block type="aimitmanufacturerblock/manufacturerblock" name="manufacturerblock" as="manufacturerblock" template="aimitmanufacturerblock/manufacturerblock.phtml" />

and I used <?php echo $this->getChildHtml('manufacturerblock')?> in my view.phtml . 我在我的view.phtml使用了<?php echo $this->getChildHtml('manufacturerblock')?>

But it seems the phtml is not included. 但似乎不包括phtml。

If you want to use the block in catalog/product/view.phtml , you need to reference product.info in the catalog_product_view handle. 如果要在catalog/product/view.phtml使用块,则需要在catalog_product_view句柄中引用product.info And I can just assume that the module is activated, the class alias is declared, the class is created and the cache is flushed 我可以假设模块已激活,声明了类别名,创建了类并刷新了缓存

Edit : Apologies, I should have followed the link to the tutorial you gave first, I see it's all about creating a new block type! 编辑 :抱歉,我应该按照你先给出的教程的链接,我看到它是关于创建一个新的块类型! However, I'll leave my answer for the moment - why do you need to create a new block type at all, there are loads of built in block types?. 但是,我现在就留下我的答案 - 为什么你需要创建一个新的块类型,有很多内置的块类型? This answer from Clockworkgeek could be useful to you too; 来自Clockworkgeek的答案也可能对您有用;

Create a new Block in Magento 在Magento中创建一个新块

Original answer; 原始答案;

The issue is your block type - the block type isn't like a variable that you define yourself, there are specific built-in Magento block types which are used to instantiate the appropriate classes. 问题是你的块类型 - 块类型不像你自己定义的变量,有特定的内置Magento块类型,用于实例化相应的类。 This SO thread will be useful to you for further explanation; 这个SO线程对您有用,可以进一步解释;

Understanding Magento Block and Block Type 了解Magento块和块类型

For another great explanation on block types read this one too; 关于块类型的另一个很好的解释也读了这个;

What Block Type for Left Column in Magento Theme? Magento主题中左栏的块类型是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM