How to show cms static block from template phtml file in Magento 2


Magento 2 static block is an effective tool to help store admins add and manage HTML code, which controls frontend display, usually for size charts, sale promotions, incentive banners, policies, etc. The main goal of creating static blocks is to save admins a lot of time diving into thousands of code lines whenever updating the websites.

In this article, we will get to know all the necessary elements for a basic understanding of static block as well as steps to call CMS static block from phtml file in Magento 2. Guarantee after the blog, you’ll find it easy to manage the incentive bar or sale promotion banner as you wish.

Static Block for Magento 2

Static Block for Magento 2

Mageplaza Better Static Block is a helpful solution to manage the content of store sites properly.

Check it out!

What Can You Obtain from Magento Static Blocks?

First of all, you need to distinguish two types of site pages: static page and dynamic page. On the one hand, static pages remain unchanged regardless of all the actions implemented on them by an admin. On the other hand, by containing various blocks, a dynamic page can be modified to display banners, pop-ups, or any other features based on its user’s actions on that page.

Normally, store owners would use static pages to show unchanged information like the store contract, return policy, company introduction, delivery regulations, etc. The dynamic page, in contrast, is used for product or checkout pages to display offers banners, promotion pop-ups, and so on.

Some Key Components of Magento 2 Static Blocks

To create a static block, please navigate to your admin panel > CMS > Manage Pages > Add New Page. There will be several components to create a new static element for your site, including:

General Information

In this field, you need to set your page’s basic information such as:

  • Page title: The page name that is displayed in the reviewer’s browser header and in the site page list.
  • SEF URL Identifier: The page identification number that requires you to insert the URL that you want to apply in a browser address bar. Remember, you must not contain spaces and use Roman symbols only in this field. If your site does not have the Roman alphabet, using a URL translation service would be fine.
  • Status: The page status: Enable or Disable.
  • Content: The static page text of information to display.

Custom Design

This is the field to customize your site design.

  • Custom Theme: Set the template theme for this page as you like. The theme between pages can be different from each other.
  • Custom Theme From/ Custom Theme To: Indicate your selected template’s term of action.
  • Layout: Choose a theme with one, two, or three columns.
  • Layout Update XML: Change the layout chosen in the previous section, and the updates will affect this particular page only.

Meta Data

In this section, it’s simply about setting “Keywords,” “Description,” and other Meta Data.

After all the modifications are completed, remember to click on the “Save Page” button and then open your newly created page in a browser to double-check how it looks.

Step to create a static block

A static block in Magento 2 can be a text or HTML code which is in any part of your site and remains unaffected by user interactions on the website. These blocks are configurable via the admin panel, offering online store owners the capability to add advertisement banners, category links, informative bars, and other valuable elements to their websites. Some administrators also utilize these blocks for showcasing social ads and other engaging features that aid in site promotion.

To create a static block in Magento, follow these steps:

  • Access the admin panel, navigate to Content > Elements > Blocks Add New Block. You will then see a page featuring various settings that can be adjusted to tailor the functionality and appearance of your block.

    • Enable Block: Choose Yes to activate the block
    • Block Title: The name of your block, which will be visible in the list of blocks within your admin panel.
    • Identifier: This field is essential, as it necessitates a unique identifier for your block.
    • Store View: Select the store views to display the static block in.
    • Block Content: This field accommodates the content you want your individual block to display, whether it’s advertisement text, information, HTML code, or other content.

Now, click Save Block to save all the changes you have made.

How to show CMS static block from template PHTML file in Magento 2

Magento 2 provides users with CMS Static Block, which is useful in showing text, photos, videos, and other materials on the webpage. Dynamic content can also be added via widgets in the static blocks. Using Magento 2 CMS Static Block enables you to edit and design those content with ease. When you have created the block and want to show it from the phtml file, this tutorial is for you.

Use the below code snippet if you want to show CMS Static Block from template phtml file in Magento 2:

echo $this->getLayout()

Display CMS Static Block In CMS Content:

Display CMS Static Block In XML:

<referenceContainer name="content"> 
    <block class="Magento\Cms\Block\Block" name="block_identifier"> 
            <argument name="block_id" xsi:type="string">block_identifier</argument> 

Hope this helpful article shows you the quick process of displaying CMS static block from template phtml file in Magento 2. If you are interested in adding a CMS Block in the Checkout page, which may seem a little troublesome, feel free to take a look at this article. In case that you have any queries about the article or any questions in general, use the comment section below!

Image Description
With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.

People also searched for

  • call static block in phtml magento 2
  • magento 2 cms block in phtml
  • magento 2 add cms block to phtml
  • magento 2 call static block in phtml
  • magento 2 call cms block in phtml
  • magento 2 get cms block in phtml
  • how to call static block in phtml file in magento 2
  • get cms block in phtml magento 2
  • get static block in phtml magento 2
  • add cms block in phtml magento 2
  • call cms block in phtml magento 2
  • magento 2 static block in phtml
  • magento 2 get static block in phtml
  • magento 2 add static block to phtml
  • magento 2 get block in phtml
  • magento 2 load cms block by identifier
  • get block in phtml magento 2
  • call cms block in phtml file magento 2
  • magento 2 render block in phtml
  • call block in phtml magento 2
  • 2.3.x, 2.4.x