🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Get Static Block Content in Block File in Magento 2

By Sanjay JethvaUpdated on May 21, 2025 1 min read

CMS blocks help to manipulate content of the Magento 2 stores. Static blocks can carry a simple text or html, CSS, Javascript to display content. It makes the reuse of the content in a modular and manageable way.

Previously, I had come up with the solution to Call CMS Static Block in Phtml File in Magento 2. Today, I will help you get static block content in block file in Magento 2.

Steps to Get Static Block Content in Block File in Magento 2:

1. Create Index.php file at Vendor\Extension\Block folder

namespace Vendor\Extension\Block;

use Magento\Framework\View\Element\Template;
use Magento\Cms\Block\Block as cmsBlock

class Index extends Template
{
    public $cms;
 
    public function __construct(Template\Context $context,cmsBlock $cmsblock)
    {
        $this->cmsblock = $cmsblock;
        parent::__construct($context);
    }
 
    public function getCmsBlock()
    {
        $cmsblock = $this->cmsblock->setBlockId('block_identifier')->toHtml();
        return $cmsblock;
      }
}

2. Write below code to get cmsBlock data in your phtml file

$block->getCmsBlock();

Simply following the above steps will help you get static block content in Magento 2 block file.

Also read: Magento 2 API – Get CMS Page Content

Happy Coding 🙂

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.