{"id":994,"date":"2020-05-10T15:32:24","date_gmt":"2020-05-10T15:32:24","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/05\/10\/pass-data-from-cms-block-to-phtml-file-in-magento-2\/"},"modified":"2025-05-22T13:11:05","modified_gmt":"2025-05-22T07:41:05","slug":"pass-data-from-cms-block-to-phtml-file-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/pass-data-from-cms-block-to-phtml-file-in-magento-2\/","title":{"rendered":"How to Pass Data From CMS Block to PHTML File in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 CMS is popular among the E-commerce store owners owing to its flexibility. It allows fulfilling the business requirements that are based on customer expectations or to improve the onsite user experience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a part of such requirement fulfilment and enriching the store frontend, the following solution to&nbsp;<em><strong>pass data from CMS block to PHTML file in Magento 2<\/strong><\/em>&nbsp;can be helpful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using the below code, one can update the category on the home page to display the subcategories, display product blocks, offers launched, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to pass data from CMS block to PHTML file in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following code in any static block:<\/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=\"\">{{block class=\"Magento\\Framework\\View\\Element\\Template\" template=\"Magento_Catalog::display-product.phtml\" product-sku=\"VVXL10\"}} \\\\ Here you can put your custom block class<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<em><strong>display-product.phtml<\/strong><\/em>&nbsp;in&nbsp;<strong>app\/design\/[Namespace]\/[Theme]\/Magento_Catalog\/templates<\/strong><\/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\n\n$productSku = $block->getData('product-sku');\n\necho \"Product SKU \".$productSku;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento 2 community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 CMS is popular among the E-commerce store owners owing to its flexibility. It allows fulfilling the business requirements that are based on customer&#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-994","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/994","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=994"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":14920,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/994\/revisions\/14920"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}