This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join the live AMA session with Adam Silverstein on open source and WordPress core! Register Now →

Use Magento Layout XML Files for Adding Custom Information to Magento Modules

Updated on December 24, 2021

2 Min Read
Magento layout xml

Magento is a robust ecommerce platform that is ideal for everyone from lay users to seasoned developers. Magento offers incredible flexibility for adding, editing and setting various information items quickly and without any fuss. This way, solutions to common problems could be deployed without worrying about time constraints and application level issues.

In this article, I will demonstrate how you could easily add Magento custom layout information in module page using the Magento layout XML file. Using this file, you can add custom titles, meta tags, keywords or a description of your Magento module page. You can easily add this custom information to all existing, core or newly created modules.

What is the Magento Module Layout File?

As the name suggests, the layout file is used for rendering the Magento frontend. This Magento custom layout XML file can be found at  app/design/frontend/your_vendor/your_theme/layout/YourModuleName.xml. Each Magento module has its own layout file. For example, the customer module has the customer.xml layout file and the catalog module has the catalog.xml layout file, etc.

By using the layout file, you can set or change the title, meta title, page keywords, and add breadcrumb to a module’s frontend. This can be accomplished by adding a few lines of code in the layout file of the module.

Cloudways Magento Hosting For Developers

Add Magento Custom Layout Info in XML file

Open the layout XML file of a module and search for the element named as <default>. Keep in mind that you will have to write the following code inside the <default> element of the layout file.

<reference name="head">
    <action method="setTitle">
        <title>Your Title</title>
    </action>
    <action method="setDescription">
        <title>Your Description</title>
    </action>
    <action method="setKeywords">
        <title>Your Keywords</title>
    </action>
</reference>

In addition to the above, you can add other custom information for a particular page of your module. For instance, you have a Location Page for your module. The Location Page will have a layout file named something like YourModule_index_location. You can just copy and paste the above XML code inside the layout file and change the respective information.

You can also add breadcrumbs to a specific page of your module. To add breadcrumbs, let’s take the example of the Location Page. You will have to add code so magento layout update xml works.

Open its layout file and add the following code:

<reference name="breadcrumbs">
    <action method="addCrumb">
        <crumbName>Home</crumbName>
        <crumbInfo>
            <label>Home</label>
            <title>Home</title>
            <link>/home</link>
        </crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>Location</crumbName>
        <crumbInfo>
            <label>Location</label>
            <title>Location</title>
            <link>/location</link>
        </crumbInfo>
    </action>
</reference>

The above code is also useful for passing breadcrumb information to the GoogleBot, helps in SEO of your Magento website in general.

The structure of the Magento Layout XML file is easy to understand and is a great way of customizing module pages in Magento. While at first, the structure of the layout file could be tricky to understand, once you begin tinkering with it, you will quickly get the hang of the idea.

Feel free to ask a question about the usage of Layout file. Just post a comment and I will get back you ASAP!

 

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdur Rahman

Abdur Rahman is the Magento whizz at Cloudways. He is growth ambitious, and aims to learn & share information about Ecommerce & Magento Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now