Magento Tutorials

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!

Click to rate this post!
[Total: 6 Average: 4.3]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

2 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

2 days ago

Magento 2: How to Add Header and Footer in Checkout

Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…

3 days ago

Understanding Flexbox Layout in React Native

Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…

5 days ago

HYVĂ„ Themes Releases: 1.3.6 & 1.3.7 – What’s New

We have brought exciting news for Magento store owners. Hyvä Themes recently released 1.3.6 and…

5 days ago

How Modern E-Commerce Platforms Leverage Docker & Kubernetes for Scalability

Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…

6 days ago