Categories: GeneralMagento 2

How to Create Custom Page Layout in Magento 2

In this article, You are going to learn about how you can create a custom page layout and manage the design of that layout with custom code guide.

Often, we are required to create a custom page layout for our custom theme or custom requirement of our Magento store for a better front-end view. However, Magento by default provides 1column, 2columns-left, 2columns-right, 3columns.

But in some cases, you need to develop a custom page layout instead of using the default page layout for your custom requirements. For homepage or any specific page you wish, you can change the page design to match your requirements and improve the page performance.

There are ways we can achieve this in Magento itself with some knowledge of coding. You need to follow the steps as described below to make custom page layouts with coding.

For example, if you want to create custom_column layout, You need to focus on two basic files,

    • layout.xml
    • page_layout/custom_column.xml

Letā€™s start with first step to locate the layout.xml file at,

app\code\Vendor\Extension\view\layout.xml

Use the code described below to create custom layout:

<?xml version="1.0" encoding="UTF-8"?>

<page_layouts xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/ PageLayout/etc/layouts.xsd">

Ā Ā Ā Ā <layout id=" custom_column">

       <label translate="true">Custom layout</label>

Ā Ā Ā Ā </layout>

</page_layouts>

With this code, your custom layout file is created in admin panel.

  • page_layout/custom_column.xml

locate the page_layout/custom_column.xml file at,

app\code\Vendor\Extension\view\page_layout\custom_column.xml

Use the below code to create the file to manage the design of page layout you created with above code:

<?xml version="1.0"?>

<layout xmlns:xsi="http://www. w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/ Layout/etc/page_layout.xsd">

Ā Ā Ā Ā Ā <update handle="1column"/>

Ā Ā Ā <referenceContainer name="page.wrapper" htmlClass="page-wrapper page-layout-1column layout-custom-column"/>

</layout>

Once you have created the custom page layout file with these codes, the first thing you need to do is clear the cache. Your custom page layout will automatically be added to the page layout list.

So, in this post we learned that using these codes, you will be able to create new custom page layouts for your custom themes or requirement so that you can achieve a better frontend view. Also, you can customize the layout to help improve page performance. Follow the steps described above and you are good to go.

Lastly, if you found this blog helpful, donā€™t forget to share it with your colleagues and Magento Friends and Let us know if you are facing any issue while implementing this code.

Happy Coding! ?

Ā 

Click to rate this post!
[Total: 10 Average: 4.6]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate šŸŽ–ļø Certified Magento DeveloperšŸ‘Øā€šŸ’». He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fondā¤ļø of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.šŸ

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

21 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

5 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago