Magento, Magento 2

How to Create Custom CMS Page Layout XML File in Magento 2

How to Create Custom CMS Page Layout XML File in Magento 2

In this tutorial, Today I will explain to how to create custom cms page layout xml file in Magento 2. When, you want to add any custom css and js in your custom cms page and your want to use layout XML file then, how you will create layout xml file for custom cms page?

You may also like this :

Steps for Create Custom CMS Page Layout XML File in Magento 2 :

1) First of all, Let’s assume that you have simple module. Now, you need to create xml file in your layout folder. Your file name should be : cms_page_view_id_<your-custom-cms-page-identifier>.xml

For ex : If your cms page identifier is custompage, then file name should be cms_page_view_id_custompage.xml


<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <!-- Add your css and js file tag here-->   
    </head> 
    <body>
            <!-- Add your reference container, ref block etc. here -->
    </body>
</page>

After create file, you just need to paste above code in that file. Now, add block, container, css, js etc. based on your requirement.

2) After that, Just clean cache and check your output.

That’s it !!!

I hope this blog is easy to understand about how to create custom cms page layout xml file in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.

Stay Safe and Stay Connected !!

Tagged ,