I have a static block called newest_product
(with content) and I would like to display it on a .phtml
file as html.
I've tried this code:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('newest_product')->toHtml();
But this nothing is being displayed.
Am I using the wrong code?
1. Navigate to Content > Elements > Widgets and press the Add Widget button. 2. Choose the CMS Static Block as a Type, set the Design Theme and press Continue.
You can get CMS Static Blocks collection by an identifier in Magento 2 by calling BlockRepositoryInterface interface. Magento\Cms\Api\BlockRepositoryInterface used for getting CMS Static Blocks in Magento 2.
If you need to override the info template with your module or theme level, you can do it with ease. Template declaration will be found from the Block class, Magento\Sales\Block\Order\Info with protected $_template variable. Add the content from the Original template with your modified changes.
Re: How to call phtml file in another phtml fileecho $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login. phtml")->toHtml();
If you have created CMS block named 'block_identifier' from admin panel. Then following will be code to call them in .phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->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