How to Call CMS Static Block in Phtml File in Magento 2

How to Call CMS Static Block in Phtml File in Magento 2

Magento 2 static blocks are helpful to admin to add and control HTML code to be displayed in the frontend. Generally, admin uses the static block for size charts, offer banners, sale promotions, return policies, etc. The entire objective of creating these static blocks is to streamline the amount of time it takes to update your site. You don’t need to dive into the hundreds of lines of code to update the changes every time!

Using Phtml file is one of the ways to call CMS static block in Magento 2. I’ll show here how to call CMS block in phtml file in Magento 2. Using the below method, you can simplify your tasks such as managing that offer bar in the store or the sale banner that you’ve put up for the festive season!

Before calling CMS block in phtml file in Magento 2, first of all, you need to create a static block:

  1. Login to Magento 2, move to Content –> Blocks. Click “Add New Block“, add below information and save configuration.
    1. Enable Block: Enable the block.
    2. Block Title: Name of the block to easily identify the purpose of creating the block.
    3. Identifier: Enter a unique block identifier.
    4. Store View: Select the store views to show the static block in.
    5. Block Content: Add content of the block.
  2. Once the static block is saved, it can be seen enlisted in the grid.

static-block

 

Now we can call the created static block in phtml file as below.

Method to call CMS static block in phtml file in Magento 2

Call your static block in phtml file:

Display CMS Static Block In CMS Content:

Display CMS Static Block In XML:

Code to show the CMS Static Block in the “Content”

Implement the above code which will save a lot of your time that can be focussed for the betterment of the business!

You may have a look at the programmatic method to call helper function in pHTML in Magento 2.

In the case of any doubts regarding the topic, please use the comments section below. I’d be happy to help you out ?

Rate the post with 5 stars if found useful.

Happy Coding ?

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

4.9
(based on 63 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

8 comments On How to Call CMS Static Block in Phtml File in Magento 2

Leave a reply:

Your email address will not be published.