Hello Magento Friends,
Welcome back to our “How To” Magento 2 technical blog series.
With Magento 2 sometimes we need to add dynamic content to our CMS pages. Calling a custom phtml file is a good move. So let us learn about Magento 2: Call Custom phtml file on all CMS Pages.
Step 1: First, you need to create cms_page_view.xml in the following path
app\code\Vendor\Extension\view\frontend\layout\cms_page_view.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="custom_phtml_in_cms" template="Vendor_Extension::call_allcms.phtml" /> </referenceContainer> </body> </page>
Step 2: Now you need to add the call_allcms.phtml file in the following path
app\code\Vendor\Extension\view\frontend\templates\call_allcms.phtml
<?php echo "Call this phtml file in all cms pages"; ?>
That’s it!
Following the above steps, you are able to call custom phtml file on all CMS pages of Magento 2. For any doubts or queries, let me know in the comment section and I will be happy to help you. Help your Magento friends by forwarding the article to them. Hit 5 stars if you found the article helpful and stay connected with us!
Happy Coding!
Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…