I've created a Custom Block based on this tutorial http://blog.magikcommerce.com/how-to-show-most-viewed-best-selling-products-in-magento-store
I would like to call the Block from my home.phtml template file.
I call my static blocks from:
<?php
$helper = Mage::helper('cms');
$source = Mage::getModel('cms/block')->load('my-block');
$processor = $helper->getPageTemplateProcessor();
$html = $processor->filter($source->getContent());
echo $html;
?>
And it works like a charm, of course! ' But how can I load dynamic blocks, in my case, inside template files.
My bestseller.phtml file is:
app/design/frontend/default/default/template/catalog/product/bestseller.phtml
And my class is:
Mage_Catalog_Block_Product_Bestseller
Go to vendor/magento/module-contact/view/frontend/templates from the root directory of your store and copy the form. phtml file to app/code/Magenticians/Modulecontact/view/frontend/templates. Now you just need to update the form.
Re: How to call phtml file in another phtml fileecho $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login. phtml")->toHtml();
Loading a block from a template file is a very bad style, but it is possible.
The dirty way from a template file
echo $this->getLayout()->createBlock('catalog/product_bestseller')->toHtml();
The clean way:
Modify the corresponding layout XML file and add the block, then refer to it with
echo $this->getChildHtml('product_bestseller');
If you want to add a block to a cms page use the Layout Xml Updates section under Design:
<reference name="content">
<block type="catalog/product_bestseller" name="product_bestseller" />
</reference>
this worked as of 1.5.1, also allows you to relocate the template
$block = $this->getLayout()
->createBlock('catalog/product_bestseller','product_bestseller',
array('template' => 'pathTo/template.phtml'));
echo $block->setBlockId('whatever')->toHtml();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With