{"id":165,"date":"2018-08-25T05:00:11","date_gmt":"2018-08-25T05:00:11","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/08\/25\/call-cms-static-block-in-phtml-file-in-magento-2\/"},"modified":"2026-04-22T15:01:15","modified_gmt":"2026-04-22T09:31:15","slug":"call-cms-static-block-in-phtml-file-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/call-cms-static-block-in-phtml-file-in-magento-2\/","title":{"rendered":"How to Call CMS Static Block in Phtml File in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 (Adobe Commerce) static blocks are helpful for the admin to add and control HTML code to be displayed in the frontend. Generally, admins use 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\u2019t need to dive into the hundreds of lines of code to update the changes every time!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using a Phtml file is one of the ways to call a CMS static block in Magento 2. I\u2019ll show here how to\u00a0call the CMS block\u00a0in\u00a0a phtml\u00a0file in Magento 2. Using the method below, you can simplify your tasks, such as managing the offer bar in the store or the sale banner that you\u2019ve put up for the festive season!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before calling the CMS block\u00a0in the phtml file in Magento 2 (Adobe Commerce), first of all, you need to create a static block:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Log in to Magento 2, move to\u00a0Content \u2013> Blocks. Click \u201cAdd New Block\u201c, add the information below, and save the configuration.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Enable Block:<\/strong>&nbsp;Enable the block.<\/li>\n\n\n\n<li><strong>Block Title:<\/strong>&nbsp;Name of the block to easily identify the purpose of creating the block.<\/li>\n\n\n\n<li><strong>Identifier:<\/strong>&nbsp;Enter a unique block identifier.<\/li>\n\n\n\n<li><strong>Store View:<\/strong>&nbsp;Select the store views to show the static block in.<\/li>\n\n\n\n<li><strong>Block Content:<\/strong>&nbsp;Add content of the block.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">2. Once the static block is saved, it can be seen listed in the grid.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2018\/08\/static-block.png\" alt=\"static-block\" class=\"wp-image-3365\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can call the created static block in phtml&nbsp;file as below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to call CMS static block in phtml file in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Call your static block in the phtml file:<\/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=\"\">&lt;?php\necho $this->getLayout()\n->createBlock('Magento\\Cms\\Block\\Block')\n->setBlockId('your_block_identifier')\n->toHtml();\n?><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Display CMS Static Block In CMS Content:<\/h3>\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=\"\">{{block class=\"Magento\\\\Cms\\\\Block\\\\Block\" block_id=\"block_identifier\"}}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Code to show the CMS Static Block in the \u201cContent\u201d<\/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=\"\">&lt;referenceContainer name=\"content\"> \n    &lt;block class=\"Magento\\Cms\\Block\\Block\" name=\"block_identifier\"> \n        &lt;arguments> \n            &lt;argument name=\"block_id\" xsi:type=\"string\">block_identifier&lt;\/argument> \n        &lt;\/arguments> \n    &lt;\/block> \n&lt;\/referenceContainer><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Implement the above code, which will save a lot of your time that can be focused on the betterment of the business! You can also simply\u00a0<a href=\"https:\/\/meetanshi.com\/blog\/call-block-in-page-builder-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">use the Page Builder to call block in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may have a look at the programmatic method to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/call-helper-function-in-phtml-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">call helper function in pHTML in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy Coding?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 (Adobe Commerce) static blocks are helpful for the admin to add and control HTML code to be displayed in the frontend. Generally, admins&#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-165","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/165","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=165"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":26351,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/165\/revisions\/26351"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}