5
votes

i have created a module and block

<block type="mymodule/mymodule" name="my_block" template="mymodule/mymodule.phtml"/>.

in catalog.xml under default theme.

I am calling this block by getChildHtml('my_block') method from catalog/product/view.phtml of default theme and it displays text from mymodule.phtml file but i dont want to call that block from view.phtml above view.phtml, Is there any way to call the above block anywhere from mymodule to display text from mymodule.phtml.

2
look for my_block in the layout xml file likely in catalog.xml and try to add the same to your template. is that what you want to call it in the template of your module? or you want to call it inside your class? - Dreaded semicolon
it depends where you want to show it. I dont think that list.phtml has some block hooks because of performance. So you should change the theme file. You may create your own theme or add it to app/design/frontend/default/default/catalog/product/ - Sergii Stotskyi
Dreaded semicolon and Serjio thank you for reply. Actually i had created my_block in catalog.xml which uses my modules phtml template file, and that template file displays in product category page and its working when i call getChildhtml("my_block") from list.phtml page. But what is other way to call that block from my modules file. - mahesh kajale
Do you want to call my_block in your own module ? where.either by php code or xml - Mahmood Rehman

2 Answers

0
votes

If you want to call your block without use of getChildHtml() you need to put your block into a content block like left,right,content, etc, and it will be rendering automatically.

0
votes

A call to method getChildHtml() loads the HTML for the child block with the name which is passed to the method.

Put your block into layout file in one of reference area like left,right and content and call that using assigned name.

try,

<?php echo $this->getChildHtml('my_block') ?>