简体   繁体   中英

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 . Now I need to use my manufacturerblock.phtml on my pruduct view page (just somewhere closed to product description text).

In local.xml (under <reference name="header"> ) I added: (edit: I tried also under <reference name="product.info"> in <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 .

But it seems the phtml is not included.

If you want to use the block in catalog/product/view.phtml , you need to reference product.info in the catalog_product_view handle. 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;

Create a new Block in 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. This SO thread will be useful to you for further explanation;

Understanding Magento Block and Block Type

For another great explanation on block types read this one too;

What Block Type for Left Column in Magento Theme?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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