{"id":16559,"date":"2018-08-30T17:18:09","date_gmt":"2018-08-30T15:18:09","guid":{"rendered":"https:\/\/belvg.com\/blog\/?p=16559"},"modified":"2019-12-04T16:53:23","modified_gmt":"2019-12-04T14:53:23","slug":"using-layout-and-xml-schema-in-magento-2","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html","title":{"rendered":"Using Layout and XML Schema in Magento 2"},"content":{"rendered":"\n<p>One of the most common tasks during a site development is changing the appearance and the structure of the pages. In Magento 2, layout XML files are used to describe the structure of the pages. Developers most commonly have to solve two basic types of tasks: modification of the existing layout files and the creation of their own. Let&rsquo;s take a closer look at these types of tasks.<\/p>\n<p><!--more--><\/p>\n<h2><strong>Creating your own layout files<\/strong><\/h2>\n<p>In Magento 2 layouts (1) are used to describe the basic structure of a web page. Containers (2) are used to create a page layout. The contents of a container can be blocks and other containers. Blocks (3) are intended for outputting the html content of a page, which is contained in their template files.<\/p>\n<p><a href=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/image23.png\"><img decoding=\"async\" loading=\"lazy\" class=\"lazy aligncenter size-full wp-image-16560\" src=\"https:\/\/belvg.com\/wp-content\/uploads\/2019\/06\/pixel.png\" data-src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/image23.png\" alt=\"Layouts, containers and blocks in Magento 2\" width=\"950\" height=\"388\" title=\"Using Layout and XML Schema in Magento 2\"><\/a><\/p>\n<p style=\"text-align: center;\">1 &ndash; layout; 2 &ndash; containers; 3 &ndash; blocks<\/p>\n<p>To create your own layout we need to complete the following 2 steps. The first one, is creating a <strong>layouts.xml<\/strong> file along the following path: <em>&lt;Your_module&gt;\/view\/&lt;area&gt;\/,<\/em>&nbsp;with the following content:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;page_layouts xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/PageLayout\/etc\/layouts.xsd\"&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;layout id=\"my-layout\"&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label translate=\"true\"&gt;My layout&lt;\/label&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;\/layout&gt;\r\n&lt;\/page_layouts&gt;<\/pre>\n<p>The next step is to add a <strong>my-layout.xml<\/strong> file along the following way: <em>&lt;Your_module&gt;\/view\/&lt;area&gt;\/page_layout\/<\/em> and fill it with the necessary content:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;layout xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_layout.xsd\"&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;update handle=\"empty\"\/&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;referenceContainer name=\"page.wrapper\"&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;container name=\"header.container\" as=\"header_container\" label=\"Page Header Container\" htmlTag=\"header\" htmlClass=\"page-header\" before=\"main.content\"\/&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;container name=\"page.top\" as=\"page_top\" label=\"After Page Header\" after=\"header.container\"\/&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;container name=\"footer-container\" as=\"footer\" before=\"before.body.end\" label=\"Page Footer Container\" htmlTag=\"footer\" htmlClass=\"page-footer\"\/&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;\/referenceContainer&gt;\r\n&lt;\/layout&gt;<\/pre>\n<p>After that our new template will be available on the administrative panel and we can use it on our website:<\/p>\n<p><a href=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/image17.png\"><img decoding=\"async\" loading=\"lazy\" class=\"lazy aligncenter size-full wp-image-16561\" src=\"https:\/\/belvg.com\/wp-content\/uploads\/2019\/06\/pixel.png\" data-src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/image17.png\" alt=\"Admin panel with a new template in Magento 2\" width=\"1182\" height=\"595\" title=\"Using Layout and XML Schema in Magento 2\"><\/a><\/p>\n<h2><strong><span style=\"color: #000000;\">Modification of the existing layout fies<\/span><\/strong><\/h2>\n<p>&nbsp;<\/p>\n<p>Magento 2 provides a number of instructions that allow you to change the layout file in almost any way. But first you need to learn how to specify layout for a particular page. You can do this in the configuration xml file of the page using the layout attribute of the root node of the page. For example, to change the default layout for the Advanced Search page from 1-column to 2-column with left bar, we need to create a file along the following way:<\/p>\n<p><em>app\/design\/frontend\/&lt;You_vendor_name&gt;\/&lt;You_theme&gt;\/Magento_CatalogSearch\/layout\/catalogsearch_advanced_index.xml. <\/em><\/p>\n<p>The file should contain the following:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;page layout=\"2columns-left\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\"&gt;\r\n...\r\n&lt;\/page&gt;<\/pre>\n<p>However, more often we don&rsquo;t have to completely change the layout of the page, but to add or remove something in the existing one. For these purposes, there is a number of tools in Magento 2 that allow us to:<\/p>\n<ul>\n<li>add and remove static resources (JavaScript, CSS, fonts) in the head section of the page;<\/li>\n<li>create and change containers;<\/li>\n<li>create and change blocks;<\/li>\n<li>set templates for blocks;<\/li>\n<li>pass arguments to blocks;<\/li>\n<li>move items (blocks and containers);<\/li>\n<li>change the order of the elements (blocks and containers);<\/li>\n<li>delete elements (blocks and containers).<\/li>\n<\/ul>\n<p>Let&rsquo;s take a look at some examples of using these instructions.<\/p>\n<h4><strong><span style=\"color: #000000;\">Adding and deleting static resources<\/span><\/strong><\/h4>\n<p>To add static resources to the page you should create the <strong>default_head_blocks.xml<\/strong> file along the following path:<\/p>\n<p><em>You_theme\/Magento_Theme\/layout\/default_head_blocks.xml.<\/em><\/p>\n<p>You can add a css file using the following instruction:<\/p>\n<pre class=\"lang:css decode:true\">&lt;css src=\"css\/my-styles.css\"\/&gt;<\/pre>\n<p>To add a locally hosted JavaScript file, you can use one of the following instructions:<\/p>\n<pre class=\"lang:js decode:true\">&lt;script src=\"Magento_Catalog::js\/sample1.js\"\/&gt;\r\n&lt;link src=\"js\/sample.js\"\/&gt;<\/pre>\n<p>To connect an external resource, you need to add the <strong>src_type<\/strong> attribute with the <strong>url<\/strong> value. For example:<\/p>\n<pre class=\"lang:css decode:true\">&lt;css src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.4\/css\/bootstrap-theme.min.css\" src_type=\"url\" \/&gt;\r\n&lt;script src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.4\/js\/bootstrap.min.js\" src_type=\"url\" \/&gt;<\/pre>\n<p>You can add a font using the link tag with the mandatory addition of the <strong>rel=&rdquo;stylesheet&rdquo;<\/strong>&nbsp;and <strong>type=&rdquo;text\/css&rdquo;<\/strong>:<\/p>\n<pre class=\"lang:css decode:true\">&lt;link rel=\"stylesheet\" type=\"text\/css\" src=\"http:\/\/fonts.googleapis.com\/css?family=Montserrat\" src_type=\"url\" \/&gt;<\/pre>\n<h4><strong><span style=\"color: #000000;\">Adding and changing containers<\/span><\/strong><\/h4>\n<p>To add a new container, you can use the following instruction:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;container name=\"you.container\" as=\"youContainer\" label=\"My Container\" htmlTag=\"div\" htmlClass=\"my-container\" \/&gt;<\/pre>\n<p><strong>Name<\/strong> is the only mandatory attribute.<\/p>\n<p>To change a container, (to add a block, for example) there is a <strong>referenceContainer<\/strong> instruction:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;referenceContainer name=\"header.panel\"&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;block class=\"YouVendor\\YouModule\\Block\\YouBlock\" name=\"new.block\" \/&gt;\r\n&lt;\/referenceContainer&gt;<\/pre>\n<h4><strong><span style=\"color: #000000;\">Adding and changing blocks. Changing the block template. Changing Block Parameters<\/span><\/strong><\/h4>\n<p>The block is created using the block instruction with the required argument name. For example:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;block class=\"Magento\\Catalog\\Block\\Product\\View\\Description\" name=\"product.info.sku\" template=\"product\/view\/attribute.phtml\" after=\"product.info.type\" \/&gt;<\/pre>\n<p>You can change the block using the <strong>referenceBlock<\/strong> instruction. Let&rsquo;s take the following block as an example:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;block class=\"Namespace_Module_Block_Type\" name=\"block.example\"&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;arguments&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument name=\"label\" xsi:type=\"string\"&gt;Block Label&lt;\/argument&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;\/arguments&gt;\r\n&lt;\/block&gt;<\/pre>\n<p>To change its argument and add a new one, we need to use the following instruction:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;referenceBlock name=\"block.example\"&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;arguments&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;The argument you want to change&nbsp;--&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument name=\"label\" xsi:type=\"string\"&gt;New Block Label&lt;\/argument&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;New argument --&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument name=\"custom_label\" xsi:type=\"string\"&gt;Custom Block Label&lt;\/argument&gt;\r\n&nbsp;&nbsp;&nbsp;&lt;\/arguments&gt;\r\n&lt;\/referenceBlock&gt;<\/pre>\n<p>If we need to assign a template to the block, there are 2 methods to do it.<\/p>\n<p>Method 1: using the template attribute:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;referenceBlock name=\"new.template\" template=\"Your_Module::new_template.phtml\"\/&gt;<\/pre>\n<p>Method 2: using an argument with the template name:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;referenceBlock name=\"new.template\"&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;arguments&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;argument name=\"template\" xsi:type=\"string\"&gt;Your_Module::new_template.phtml&lt;\/argument&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/arguments&gt;\r\n&lt;\/referenceBlock&gt;<\/pre>\n<p>The <strong>new_template.phtml<\/strong>&nbsp;in the demonstrated examples is a path to the template file relative to the <strong>template<\/strong> folder <em>(&lt;your_module&gt;\/view\/&lt;area&gt;\/templates or &lt;your_theme&gt;\/&lt;Your_Module&gt;\/templates)<\/em>.<\/p>\n<p>It should be noted that templates specified in the first way have a higher priority. This means that the value specified in the template attribute will overwrite the one specified with the argument.<\/p>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/store.belvg.com\/\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/Magento-store.belvg_.com_.png\" width=\"481\" height=\"480\" alt=\"Magento store.belvg.com\" class=\"module_image\" title=\"Using Layout and XML Schema in Magento 2\"><div class=\"module_content_part\"><h3 class=\"title\">BelVG Magento Store<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG extensions<\/p><a href=\"https:\/\/store.belvg.com\/\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Visit our store<\/span><\/a><\/div><\/div><\/div>\n<h4><strong><span style=\"color: #000000;\">Changing order, moving and deleting blocks and containers<\/span><\/strong><\/h4>\n<p>You can change the order of the element within the parent using the <strong>before<\/strong> and <strong>after<\/strong> attributes. For attribute values, you must specify the name of the element, before or after which we want to place the element we need.<\/p>\n<p>With the help of the move instruction, we can not only change the order of the element, but also change its parent. For example, the following instruction will move the block named <strong>product.info.review<\/strong> to a container named <strong>product.info.main<\/strong> and place it before the container named <strong>product.info.price<\/strong>:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;move element=\"product.info.review\" destination=\"product.info.main\" before=\"product.info.price\"\/&gt;<\/pre>\n<p>You can delete a block or a container using the remove attribute of the <strong>referenceBlock<\/strong> or <strong>referenceContainer<\/strong> instructions respectively. For example, you can delete the <strong>catalog.compare.sidebar<\/strong> block using the following instruction:<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;referenceBlock name=\"catalog.compare.sidebar\" remove=\"true\" \/&gt;<\/pre>\n<p>Thank you for reading, hope everything was clear. Please leave your comments and questions in the comment section below and I will get in touch as soon as possible.<\/p>\n<p>Check out BelVG&rsquo;s quality Magento extensions <a href=\"https:\/\/store.belvg.com\/\" target=\"_blank\" rel=\"noopener\">at our official store<\/a>.<\/p>\n\n","protected":false},"excerpt":{"rendered":"Using Layout and XML Schema in Magento 2. Describing how to create a new layout XML file and pass variables from layout to block.","protected":false},"author":82,"featured_media":16562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[474,491,389,524],"tags":[],"class_list":["post-16559","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-ecommerce","category-magento-2","category-magento2-development","category-magento-speed-optimization","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learn how to use Layout and XML schema in Magento 2. Create a new layout XML file and pass variables from layout to block with the help of our Magento blog.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Andrey Litvin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#article\",\"name\":\"How to Use Layout and XML Schema in Magento 2 | BelVG Blog\",\"headline\":\"Using Layout and XML Schema in Magento 2\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/1Using_Layout_and_XML_Schema_in.jpg\",\"width\":770,\"height\":433,\"caption\":\"Using Layout and XML Schema in Magento 2\"},\"datePublished\":\"2018-08-30T17:18:09+02:00\",\"dateModified\":\"2019-12-04T16:53:23+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#webpage\"},\"articleSection\":\"ECOMMERCE, Magento 2, Magento 2 Development, Magento Speed Optimization, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"name\":\"Magento 2 Development\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"position\":2,\"name\":\"Magento 2 Development\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#listItem\",\"name\":\"Using Layout and XML Schema in Magento 2\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#listItem\",\"position\":3,\"name\":\"Using Layout and XML Schema in Magento 2\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento2-development#listItem\",\"name\":\"Magento 2 Development\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin\",\"name\":\"Andrey Litvin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e1a6e3c80cb940fddb65016d94b015cd951b4a8a9cd7227565131f28ea95c7a0?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Andrey Litvin\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html\",\"name\":\"How to Use Layout and XML Schema in Magento 2 | BelVG Blog\",\"description\":\"Learn how to use Layout and XML schema in Magento 2. Create a new layout XML file and pass variables from layout to block with the help of our Magento blog.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/1Using_Layout_and_XML_Schema_in.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html\\\/#mainImage\",\"width\":770,\"height\":433,\"caption\":\"Using Layout and XML Schema in Magento 2\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/using-layout-and-xml-schema-in-magento-2.html#mainImage\"},\"datePublished\":\"2018-08-30T17:18:09+02:00\",\"dateModified\":\"2019-12-04T16:53:23+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to Use Layout and XML Schema in Magento 2 | BelVG Blog","description":"Learn how to use Layout and XML schema in Magento 2. Create a new layout XML file and pass variables from layout to block with the help of our Magento blog.","canonical_url":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#article","name":"How to Use Layout and XML Schema in Magento 2 | BelVG Blog","headline":"Using Layout and XML Schema in Magento 2","author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/1Using_Layout_and_XML_Schema_in.jpg","width":770,"height":433,"caption":"Using Layout and XML Schema in Magento 2"},"datePublished":"2018-08-30T17:18:09+02:00","dateModified":"2019-12-04T16:53:23+02:00","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#webpage"},"articleSection":"ECOMMERCE, Magento 2, Magento 2 Development, Magento Speed Optimization, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","name":"Magento 2 Development"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","position":2,"name":"Magento 2 Development","item":"https:\/\/belvg.com\/blog\/category\/magento2-development","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#listItem","name":"Using Layout and XML Schema in Magento 2"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#listItem","position":3,"name":"Using Layout and XML Schema in Magento 2","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento2-development#listItem","name":"Magento 2 Development"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author","url":"https:\/\/belvg.com\/blog\/author\/andrey-litvin","name":"Andrey Litvin","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/e1a6e3c80cb940fddb65016d94b015cd951b4a8a9cd7227565131f28ea95c7a0?s=96&d=mm&r=g","width":96,"height":96,"caption":"Andrey Litvin"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#webpage","url":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html","name":"How to Use Layout and XML Schema in Magento 2 | BelVG Blog","description":"Learn how to use Layout and XML schema in Magento 2. Create a new layout XML file and pass variables from layout to block with the help of our Magento blog.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/08\/1Using_Layout_and_XML_Schema_in.jpg","@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html\/#mainImage","width":770,"height":433,"caption":"Using Layout and XML Schema in Magento 2"},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html#mainImage"},"datePublished":"2018-08-30T17:18:09+02:00","dateModified":"2019-12-04T16:53:23+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"16559","title":"How to Use Layout and XML Schema in Magento 2 | #site_title","description":"Learn how to use Layout and XML schema in Magento 2. Create a new layout XML file and pass variables from layout to block with the help of our Magento blog.","keywords":[{"label":"layout","value":"layout"},{"label":"xml","value":"xml"},{"label":"schema","value":"schema"},{"label":"variables","value":"variables"},{"label":"container","value":"container"},{"label":"block","value":"block"},{"label":"css","value":"css"},{"label":"structure","value":"structure"},{"label":"magento","value":"magento"},{"label":"ecommerce","value":"ecommerce"}],"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:37:05","updated":"2026-11-03 18:37:05"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento2-development\" title=\"Magento 2 Development\">Magento 2 Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUsing Layout and XML Schema in Magento 2\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento 2 Development","link":"https:\/\/belvg.com\/blog\/category\/magento2-development"},{"label":"Using Layout and XML Schema in Magento 2","link":"https:\/\/belvg.com\/blog\/using-layout-and-xml-schema-in-magento-2.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/16559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/82"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=16559"}],"version-history":[{"count":1,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/16559\/revisions"}],"predecessor-version":[{"id":25132,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/16559\/revisions\/25132"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/16562"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=16559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=16559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=16559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}