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

How to Pass Data From CMS Block to PHTML File in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

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.

As a part of such requirement fulfilment and enriching the store frontend, the following solution to pass data from CMS block to PHTML file in Magento 2 can be helpful.

Using the below code, one can update the category on the home page to display the subcategories, display product blocks, offers launched, etc.

Method to pass data from CMS block to PHTML file in Magento 2:

Add the following code in any static block:

{{block class="Magento\Framework\View\Element\Template" template="Magento_Catalog::display-product.phtml" product-sku="VVXL10"}} \\ Here you can put your custom block class

Create display-product.phtml in app/design/[Namespace]/[Theme]/Magento_Catalog/templates

<?php

$productSku = $block->getData('product-sku');

echo "Product SKU ".$productSku;

That’s it.

Feel free to share the solution with Magento 2 community via social media.

Thank you.

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.