{"id":749,"date":"2020-01-06T07:08:30","date_gmt":"2020-01-06T07:08:30","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/01\/06\/how-to-get-static-block-content-in-block-file-in-magento-2\/"},"modified":"2025-05-21T17:56:38","modified_gmt":"2025-05-21T12:26:38","slug":"how-to-get-static-block-content-in-block-file-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/how-to-get-static-block-content-in-block-file-in-magento-2\/","title":{"rendered":"How to Get Static Block Content in Block File in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Previously, I had come up with the solution to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/call-cms-static-block-in-phtml-file-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Call CMS Static Block in Phtml File in Magento 2<\/a>. Today, I will help you <em><strong>get static block content in block file in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to&nbsp;Get Static Block Content in Block File in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create <strong>Index.php<\/strong> file at <strong>Vendor\\Extension\\Block<\/strong>&nbsp;folder<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace Vendor\\Extension\\Block;\n\nuse Magento\\Framework\\View\\Element\\Template;\nuse Magento\\Cms\\Block\\Block as cmsBlock\n\nclass Index extends Template\n{\n    public $cms;\n \n    public function __construct(Template\\Context $context,cmsBlock $cmsblock)\n    {\n        $this->cmsblock = $cmsblock;\n        parent::__construct($context);\n    }\n \n    public function getCmsBlock()\n    {\n        $cmsblock = $this->cmsblock->setBlockId('block_identifier')->toHtml();\n        return $cmsblock;\n      }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Write below code to get cmsBlock data in&nbsp;your <strong>phtml<\/strong> file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$block-&gt;getCmsBlock();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Simply following the above steps will help you get static block content in Magento 2 block file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Also read:<\/strong> <a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-cms-page-content\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API \u2013 Get CMS Page Content<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy Coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=749"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":14008,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/749\/revisions\/14008"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}