Layout Update Examples in Magento 2

Posted by

According to previous article about block types, we all know that block types play a very important role in every online stores. In Magento 2, admin control these block types with custom layout instructions. Full syntax of the intrucstions 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 operating Magento store.

Full Syntax

Simplified Syntax

page/template_links

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.

  • removeLinkByUrl($url)

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.

cms/block

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.

core/text

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[…]]>

page/html_welcome

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 configure this block type in the settings, a specified welcome message will display on screen.

Leave a Reply

Your email address will not be published. Required fields are marked *