The Magento custom layout update plays an essential role in every e-commerce website. In Magento 2, admins use custom layout instructions to control block types.
The full syntax of the instructions must be used to specify each action. However, this action might be time-consuming sometimes.
Therefore, in this article, we will go through simplified syntax that corresponds exactly to the full one to save time in Magento custom layout update.
There are two notable actions in this block type.
addLink($label, $url, $title, $prepare
This action is to add on one link to the end of the list of links available. Please inform the data as following: $label for link caption, $url for link URL, $title for link tooltip, and $prepare must be “true” if admin want to prepare the URL, or convert it from a shortened URL to the full one. For instance, a the new page will change to BASE_URL/newpage if $prepare is true. After this action, a new link will appear on the list.
In contrast to addLink, this action is to delete a link in the list by its URL. Admin must remember that the URL used in this action must be correctly specified and matches corresponding URL that you want to delete.
The action that can be done in this block type is setBlockID($blockId). This action is to identify the ID of a particular CMS block in page. Therefore, when the page is displayed, the content of that block can be found and shown.
In Magento 2, in order to place a free form text from outside directly into the template, admin use a core/text action called addText($textContent). $textContent is where admin identify the whole text that you want to be displayed on the block. To ensure that this action works well in your site, the layout update instructions must be a valid XML statement. In case the text contains a HTML tags, you should use <![CDATA[…]]>
In Magento 2, in order to copy the “Welcome, <USERNAME>!” message that is usually situated in the header block, admin can use page/html_welcome. If admin configures this block type in the settings, a specified welcome message will display on the screen.
In conclusion, instead of spending much time on using full syntax, we can use some regular simplified syntax for custom layout update in Magento, especially Magento 2 stores. It can save your time much better and you can operate your online store without difficulties.
We hope that this article is informative enough to give you a clear overview of Magento custom layout update and some specific examples for better understanding.
If you need further information about the custom layout update in Magento, please contact us. We’re glad to answer anytime! Thanks for reading!