{"id":1441,"date":"2017-09-23T21:55:03","date_gmt":"2017-09-23T21:55:03","guid":{"rendered":"http:\/\/inchoo.net\/?p=29580"},"modified":"2017-09-23T23:00:17","modified_gmt":"2017-09-23T23:00:17","slug":"bypassing-magento-2-layout-update-restrictions-in-admin","status":"publish","type":"post","link":"https:\/\/www.sushilkumar.ind.in\/blog\/magento-2\/bypassing-magento-2-layout-update-restrictions-in-admin\/","title":{"rendered":"By passing Magento 2 layout update restrictions in Admin"},"content":{"rendered":"<p>Magento\u2019s layout system has been vastly improved in Magento 2 to be\u00a0more accessible, more powerful and to be more streamlined. But, for some reason, only a very small subset of layout functions is made available for use in Magento 2 Admin (category layout XML updates, to be more precise). In this article, we\u2019re going to show a very simple way of bypassing this pesky restriction.<\/p>\n<p>&nbsp;<\/p>\n<h3>Layout update restrictions in Magento 2 Admin<\/h3>\n<p>In the interest of keeping the example simple and straightforward, let\u2019s say we want to remove the page title element from a specific category. In Magento 2 admin, in the category layout update XML field we add the following line.<\/p>\n<pre class=\"ish\"><code class=\"language-xml\"><span class=\"sc3\"><span class=\"re1\">&lt;referenceBlock<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"page.main.title\"<\/span> <span class=\"re0\">remove<\/span>=<span class=\"st0\">\"true\"<\/span> <span class=\"re2\">\/&gt;<\/span><\/span><\/code><\/pre>\n<p>And when we click save, we get the following error:<\/p>\n<blockquote><p>Please correct the XML data and try again. Element \u2018referenceBlock\u2019: This element is not expected. Expected is one of (referenceContainer, container, update, move ). Line: 1<\/p><\/blockquote>\n<p>It\u2019s important to note that this XML would be valid if added using XML files in a theme. It seems that different standards apply for the layout update field in Magento 2 Admin and for the theme layout files.<\/p>\n<p>So, only the following XML is allowed:<\/p>\n<ul>\n<li data-listid=\"1\" data-aria-posinset=\"1\" data-aria-level=\"1\">referenceContainer \u2013 we can reference existing containers<\/li>\n<li data-listid=\"1\" data-aria-posinset=\"2\" data-aria-level=\"1\">container \u2013 we can create new containers<\/li>\n<li data-listid=\"1\" data-aria-posinset=\"3\" data-aria-level=\"1\">update \u2013 we can include various layout handles<\/li>\n<li data-listid=\"1\" data-aria-posinset=\"4\" data-aria-level=\"1\">move \u2013 we can move existing blocks around<\/li>\n<\/ul>\n<p>This info will help us bypass the restriction.<\/p>\n<h3>Bypassing the layout update restrictions<\/h3>\n<p>We can simply bypass this restriction by wrapping our <em>referenceBlock<\/em>\u00a0code in\u00a0<em>referenceContainer<\/em>\u00a0code. But we need to find the container which contains our page title element. By doing a simple search in IDE, we find the following code snippet.<\/p>\n<pre class=\"ish\"><code class=\"language-xml\"><span class=\"sc3\"><span class=\"re1\">&lt;referenceContainer<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"columns.top\"<\/span><span class=\"re2\">&gt;<\/span><\/span>\r\n<span class=\"sc-1\">&lt;!-- ... --&gt;<\/span> <span class=\"sc3\"><span class=\"re1\">&lt;block<\/span> <span class=\"re0\">class<\/span>=<span class=\"st0\">\"Magento\\Theme\\Block\\Html\\Title\"<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"page.main.title\"<\/span> <span class=\"re0\">template<\/span>=<span class=\"st0\">\"html\/title.phtml\"<\/span><span class=\"re2\">\/&gt;<\/span><\/span> <span class=\"sc3\"><span class=\"re1\">&lt;container<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"page.messages\"<\/span> <span class=\"re0\">htmlTag<\/span>=<span class=\"st0\">\"div\"<\/span> <span class=\"re0\">htmlClass<\/span>=<span class=\"st0\">\"page messages\"<\/span><span class=\"re2\">&gt;<\/span><\/span> <span class=\"sc3\"><span class=\"re1\">&lt;block<\/span> <span class=\"re0\">class<\/span>=<span class=\"st0\">\"Magento\\Framework\\View\\Element\\Template\"<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"ajax.message.placeholder\"<\/span> <span class=\"re0\">template<\/span>=<span class=\"st0\">\"Magento_Theme::html\/messages.phtml\"<\/span><span class=\"re2\">\/&gt;<\/span><\/span> <span class=\"sc3\"><span class=\"re1\">&lt;block<\/span> <span class=\"re0\">class<\/span>=<span class=\"st0\">\"Magento\\Framework\\View\\Element\\Messages\"<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"messages\"<\/span> <span class=\"re0\">as<\/span>=<span class=\"st0\">\"messages\"<\/span> <span class=\"re0\">template<\/span>=<span class=\"st0\">\"Magento_Theme::messages.phtml\"<\/span><span class=\"re2\">\/&gt;<\/span><\/span> <span class=\"sc3\"><span class=\"re1\">&lt;\/container<span class=\"re2\">&gt;<\/span><\/span><\/span>\r\n<span class=\"sc-1\">&lt;!-- ... --&gt;<\/span>\r\n<span class=\"sc3\"><span class=\"re1\">&lt;\/referenceContainer<span class=\"re2\">&gt;<\/span><\/span><\/span><\/code><\/pre>\n<p>We use the <em>columns.top<\/em> container and reference it in our Layout Update XML in Admin and wrap it around our initial code.<\/p>\n<pre class=\"ish\"><code class=\"language-xml\"><span class=\"sc3\"><span class=\"re1\">&lt;referenceContainer<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"columns.top\"<\/span><span class=\"re2\">&gt;<\/span><\/span> <span class=\"sc3\"><span class=\"re1\">&lt;referenceBlock<\/span> <span class=\"re0\">name<\/span>=<span class=\"st0\">\"page.main.title\"<\/span> <span class=\"re0\">remove<\/span>=<span class=\"st0\">\"true\"<\/span> <span class=\"re2\">\/&gt;<\/span><\/span>\r\n<span class=\"sc3\"><span class=\"re1\">&lt;\/referenceContainer<span class=\"re2\">&gt;<\/span><\/span><\/span><\/code><\/pre>\n<p>When we save this configuration, we do not get any errors on the category page in Admin and the page title block is removed on that specific category.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29583\" src=\"\/\/www.sushilkumar.ind.in\/blog\/wp-content\/uploads\/2017\/09\/bypassing-magento-2-layout-update-restrictions-in-admin.png\" alt=\"\" width=\"614\" height=\"384\" \/><\/p>\n<h3>Conclusion<\/h3>\n<p>We hope to see these restrictions either removed from Magento 2 Admin XML layout update fields or better documentation that will explain the behavior in more detail. Magento 2 Admin would most certainly benefit of having unrestricted layout update features. Until then, we can hopefully use this bypass safely and hope that it\u2019s upgrade-proof.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"\/\/www.sushilkumar.ind.in\/custome-devlopment\/\">Do you need any custom Development Click here and fill the form with full your requirement<\/a> and after i will send the quotes of your work requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento&#8217;s layout system has been vastly improved in Magento 2 to be\u00a0more accessible, more powerful and to be more streamlined. But, for some reason, only a very small subset of layout functions is made available for use in Magento 2 Admin (category layout XML updates, to be more precise). In this article, we&#8217;re going to&#8230;<br \/>\nThe post Bypassing Magento 2 layout update restrictions in Admin appeared first on Inchoo. Do you need any custome Development Click here and fill the form with full your requirement  and after i will send the quotes of your work requirements&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":1442,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[255,225,264,20,307,273,308],"tags":[259,230,267,22,309,276,310],"class_list":["post-1441","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-administration","category-frontend","category-layout","category-magento-2","category-magento-administration","category-tips","category-xml-layout","tag-administration","tag-frontend","tag-layout","tag-magento-2","tag-magento-administration","tag-tips","tag-xml-layout"],"jetpack_publicize_connections":[],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-content\/uploads\/2017\/09\/bypassing-magento-2-layout-update-restrictions-in-admin.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p99pkJ-nf","_links":{"self":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/1441"}],"collection":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/comments?post=1441"}],"version-history":[{"count":0,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/1441\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media\/1442"}],"wp:attachment":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media?parent=1441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/categories?post=1441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/tags?post=1441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}