In Magento 2, a change related to product category pages, product pages or content page can be taken when admins apply a set of custom layout updates. For example: <block> is to build an additional block, <reference> is to edit an existing content or <action> to allow an action done to blocks, etc.
Please note that any performance that can change the visual and structural composition of pages can be put on only when its related entity works well in the frontend of the store. This type of entity might be a product, a category or CMS page.
A valid custom layout update instruction must contain well-developed XML tags, without the <?xml …> declaration and root tag. Like other XML, this type of tag must either be empty or closed correctly. Follow the below instance if you are not sure:
Let’s take a look at some prevalent layout updates in Magento 2:
This type of layout update is to build up a new block inside an existing context. The arrangement of initialization location of blocks on the page is defined by layout block nesting. In this tag, type and name are required value, while the others are optional.
Its value is block class path, identifying a class of the block. Therefore, admin can look at the following list that contains the available block types at that time.
This is valued as a block name identifier. Admin can assign the name of block that consists of the attribute in this section. Please remember that a newly-created block will replace an existing block that has the same name. Admin can also look at the following list that contains the available block types at that time.
When admin want to arrange a block before another block, admin specify the latter block in the block name. Or admin can use “-” to make a block before all the rest.
Completely opposed to before, this action will make a block after another block by typing the former block in the block name or use “-” to make a block after all other blocks.
This is valued as a template filename to define a specific block type. In case admin do not know how to see the list of template files, he/she can use a template value required for any type of block in the list below.
This is valued as a block alias, by which a block that contains specified attribute will be addressed. In some circumstances, a particular type of block needs to be assigned with the alias.
In Magento 2 stores, <reference> tag will make a change to all included instructions assigned to a specified block in the context. The <reference> tag is empty if there is no use, because only the children instructions are affected in this case.
In this tag, admin just need to remember to enter the block name that needs to edit in the name section.
This instruction is used to call a block’s public method, by which a third-party applications are allowed to read and write to a system. In Magento 2 stores, this tag will assign an action to the block during its generation. By this, a translation of action child tags is made into block method arguments. The number of methods that are available is determined by block implementation such as public method of the block class.
Admin needs to enter the name of public method that will be called during the block generation.
As its name, this instruction is to remove an existing block in the layout by typing its name in the name field.
By using <extend> instruction, admin will carry out final modification to blocks. These blocks must be a part of the layout. Admin can change all the attributes in the <block> instruction excluding the block name. Moreover, the parent block in the layout can be changed by using a special attribute parent. To do this, admin just have to enter the name of new parent of block in the <extend> section.
Like <block> instruction, admin must to enter the name of extended block here.
If there is any other specific attribute, enter here
This section is valued as a block name, therefore, admin can enter the name of the parent block here. After then, the new block will become parent of the previously referenced block.