Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a block in a phtml instead of through a layout?

Tags:

magento

I have disabled layout for the wishlist block:

<block type="catalog/product_view" name="product.info.addtoto" as="addtoto" template="catalog/product/view/addto.phtml"/>

I now want to call that block in the phtml instead of add it to another layout.

How do I call it directly?

like image 685
Chris Avatar asked Apr 26 '11 20:04

Chris


People also ask

How do you call a CMS block in XML?

Except for displaying CMS block on CMS Page or CMS Block, showing it on category page there is an option to call CMS block programmatically using XML file. You need to replace "my_cmsblock_identifier" with your CMS block Identifier or ID (we recommend to use Identifier).


1 Answers

While Prattski is correct that this is poor form (am I'm upvoting as such), there have been times when developing when either this has been a valuable debugging technique, or it made the difference of several hours of programming. In that spirit, this is the bad habit way of doing it:

<?php print $this->getLayout()
                 ->createBlock("catalog/product_view")
                 ->setTemplate("catalog/product/view/addto.phtml")
                 ->toHtml(); ?>

Use sparingly, if at all.

like image 53
Joe Mastey Avatar answered Sep 21 '22 07:09

Joe Mastey