{"id":910,"date":"2020-03-29T06:02:31","date_gmt":"2020-03-29T06:02:31","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/03\/29\/call-phtml-file-in-cms-static-block-in-magento-2\/"},"modified":"2025-05-22T14:39:24","modified_gmt":"2025-05-22T09:09:24","slug":"call-phtml-file-in-cms-static-block-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/call-phtml-file-in-cms-static-block-in-magento-2\/","title":{"rendered":"Get The Easiest Way To Call Phtml File In CMS Static Block In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Earlier I posted 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>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And today, the below code shows how to&nbsp;<em><strong>call Phtml file in CMS static block in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use this method to call the Phtml file on any page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, you want to call an Instagram image on a page in your Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can add and control HTML code to be displayed in the frontend using CMS static blocks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 has the MVC architecture where the Phtml files have the view part of the code while the block classes contain its related logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to call Phtml file in CMS static block in Magento 2:<\/h2>\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\\Framework\\View\\Element\\Template\" template=\"Vendor_Extension::myfile.phtml\"}}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the post with fellow developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier I posted the solution to&nbsp;call CMS static block in phtml file in Magento 2. And today, the below code shows how to&nbsp;call Phtml file&#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-910","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/910","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=910"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/910\/revisions"}],"predecessor-version":[{"id":15002,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/910\/revisions\/15002"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}