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.
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!
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]