How to show cms static block from template phtml file in Magento 2

Are you wondering how to show CMS Static Block from template `phtml` file in Magento 2? Here you are, check this effective intrucstion out.

Magento 2 provides users with CMS Static Block, which is useful in showing text, photos, videos, and other materials on the webpage. Dynamic content can also be added via widgets in the static blocks. Using Magento 2 CMS Static Block enables you to edit and design those content with ease. When you have created the block and want to show it from the phtml file, this tutorial is for you.

Use the below code snippet if you want to show CMS Static Block from template phtml file in Magento 2:

echo $this->getLayout()
          ->createBlock('Magento\Cms\Block\Block')
          ->setBlockId('your_block_identifier')
          ->toHtml();

For another block within CMS Block in Magento 2, please use the below code to show it.

{{block class="Magento\Cms\Block\Block" block_id="your_block_identifier"}}

Hope this helpful article shows you the quick process of displaying CMS static block from template phtml file in Magento 2. If you are interested in adding a CMS Block in the Checkout page, which may seem a little troublesome, feel free to take a look at this article. In case that you have any queries about the article or any questions in general, use the comment section below!

Explore Mageplaza Better Static Block extension

Enjoyed the tutorial? Spread it to your friends!

magento-2-tutorial
show
cms
static
block
template
phtml
file

Sam Thomas
Sam Thomas

CEO and Founder of Mageplaza. Pursueing a simple and healthy lifestyle. A friend, a husband and a dad of two children, a trainer and an influencer wannabe. He is a big fan of sports and travel, also.

People also searched for

  • call static block in phtml magento 2
  • magento 2 cms block in phtml
  • magento 2 add cms block to phtml
  • magento 2 call static block in phtml
  • magento 2 call cms block in phtml
  • magento 2 get cms block in phtml
  • how to call static block in phtml file in magento 2
  • get cms block in phtml magento 2
  • get static block in phtml magento 2
  • add cms block in phtml magento 2
  • call cms block in phtml magento 2
  • magento 2 static block in phtml
  • magento 2 get static block in phtml
  • magento 2 add static block to phtml
  • magento 2 get block in phtml
  • magento 2 load cms block by identifier
  • get block in phtml magento 2
  • call cms block in phtml file magento 2
  • magento 2 render block in phtml
  • call block in phtml magento 2
  • 2.2.x, 2.3.x, 2.4.x