Contents

What’s your reaction?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink1
Contents
In Magento 2 layout (1) is used to describe the structure of the website. Container (2) is used to create the elements of the page. It can contain blocks and other containers. Block (3) is used to render the html content of the page contained in the templates .phtml . files
A block is a unit that makes up a web page, anything tangible that the user sees. For example login form, shopping cart… It links between a block class (containing logic) to get data and a template file (.phtml) to display the content. A block can have children or grandchildren, chit…
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml"/>
You can use <argument></argument> to pass arguments to a class variable.
<referenceBlock name="footer_links"> <block class="Magento\Framework\View\Element\Html\Link\Current" name="helloworld-link"> <arguments> <argument name="label" translate="true" xsi:type="string">Helloworld landing</argument> <argument name="path" xsi:type="string">helloworld/index/index</argument> </arguments> </block></referenceBlock>
Above, I passed two parameters, label and path, with corresponding values to the Current class to create a path in the footer.
Container can be understood as a container, an outer wrapper or can wrap child elements into an html tag. It does not contain any content. It is used as a container to hold containers or blocks. If there are no child blocks, it will not be displayed outside the frontend.
<container name="div.sidebar.additional" htmlTag="div" htmlClass="sidebar sidebar-additional" after="div.sidebar.main"> <container name="sidebar.additional" as="sidebar_additional" label="Sidebar Additional"/></container>
Simply put, these two guys are similar in essence as they update the same block or container respectively. For example, <referenceContainer name=”content”> means I want to update <container name=”content”> again. That is, what you write will overwrite the original element.
<referenceBlock name="block.name" remove="true" />
Update ? Specifically, what can we do?
Move the block or container to another element you specify. Will be ignored if element is undefined
<move element="name.of.an.element" destination="name.of.destination.element" as="new_alias" after="name.of.element.after" before="name.of.element.before"/>
Used to remove static files like css, js linked to the web page in the <head> tag.
<head> <remove src="css/styles-m.css" /> <remove src="my-js.js"/> <remove src="Magento_Catalog::js/compare.js" /> <remove src="http://fonts.googleapis.com/css?family=Montserrat" /></head>