How to Show Cms Static Block From Template phtml File in Magento 2

How-to-Show-Cms-Static-Block-From-Template-phtml-File-in-Magento-2

 Hey, Magento buddies 

 In today’s learning tutorial, we will learn about How to Show Cms Static Block From Template phtml File in Magento 2.

CMS Static Blocks are an excellent way to display various information to your consumer. CMS Static Blocks help to get more consumer’s attention to specific products and also make your Magento 2 store or website more attractive. You can show CMS Static Blocks practically on each and every page of your Magento 2 website and Magento 2 store.

If you don’t want to consume too much time in configuring CMS Static Block, then you can call CMS Static Block in phtml or by using XML file layout. Let’s go step by step.

Steps to Show Cms Static Block From Template phtml File in Magento 2

Step 1: Add the below code in your phtml file when you show Static block

<?php
         echo $this->getLayout()
        ->createBlock(\Magento\Cms\Block\Block::class)
        ->setBlockId('block_identifier_here')
	->toHtml();
	//change  block_identifier_here with Your CMS Block Identifier
?>

Step 2: Add below code CMS static block in your CMS page.

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

Final words

So, in this tutorial article, we learn How to Show Cms Static Block From Template phtml File in Magento 2. If any confusion occurs, feel free to reach us via the comments. Share it with your Magento buddies.

Happy learning!

Previous Article

How to Add Top Link in Magento 2

Next Article

OsCommerce vs. Magento: Determining the Best Fit for Your Business

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨