I'm trying to create a custom layout based on 2columns-left.xml. The layout was created correctly and I can select it from the Admin. This is what I did so far:
I created the layouts.xml file THEME/Magento_Theme/layouts.xml
And then I created the customlayout.xml file THEME/Magento_Theme/page_layout/customlayout.xml
With the same content as:
vendor/magento/module-theme/view/frontend/page_layout/2columns-left.xml
The problem is that the layout has only 1 column, instead of 2columns-left, why?
Thank you.
This is a repeat of the Custom Layout extending 2 columns left, there was no response and I would like to get this issue solved thanks!
-
can you please share your layout file code?sudo55– sudo552019年01月15日 22:05:56 +00:00Commented Jan 15, 2019 at 22:05
-
I tried the code below. I have a cms page that i am trying to give a custom layout but i want to keep the two column platform. I have a cms page with a hierarchy that I would like to keep on the page. Do i have to include anything more than just the code below to get that sidebar to appear again.Brandon Irwin– Brandon Irwin2019年01月17日 22:34:27 +00:00Commented Jan 17, 2019 at 22:34
-
Can you provide anymore insight to accomplish this? @AliEjazBrandon Irwin– Brandon Irwin2019年01月20日 00:36:51 +00:00Commented Jan 20, 2019 at 0:36
-
@BrandonIrwin Did you get solution? I had face same issue.Mehta Prem– Mehta Prem2020年09月20日 07:36:16 +00:00Commented Sep 20, 2020 at 7:36
-
I opened up a ticket with Magento about this in working with a few Magento Devs I know and this is what they came up with. I am not sure if they updated the devdocs since then I told them that would be helpful. Hope this helps Hope this information will help. The referenced documentation page (devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/…) contains an example of how to create a new layout, which declares an empty container for the footer content which will need to be designed.Brandon Irwin– Brandon Irwin2020年09月21日 15:04:24 +00:00Commented Sep 21, 2020 at 15:04
2 Answers 2
You need to change your handle like,
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
<update handle="2columns-left"/>
<referenceContainer name="columns">
<container name="div.sidebar.main" htmlTag="div" htmlClass="sidebar sidebar-main" after="main">
<container name="sidebar.main" as="sidebar_main" label="Sidebar Main"/>
</container>
<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>
</referenceContainer>
</layout>
-
So when i do this my page appears blank should it at least show something?Brandon Irwin– Brandon Irwin2019年01月16日 14:00:02 +00:00Commented Jan 16, 2019 at 14:00
-
it is missing </layout>Romer Rios– Romer Rios2020年11月24日 23:01:42 +00:00Commented Nov 24, 2020 at 23:01
The problem is that it doesn't include the page-layout-2columns-left body class. Because it includes the new layout class e.g. page-layout-my-layout-file-name. And the css for the 2columns-left layout is written with the page-layout-2columns-left class
To add this class to the body, you have to create a plugin for the Magento\Framework\View\Result\Page here is the code.
First create the di.xml in Vendor/ModuleName/etc/frontend/di.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* di
*
* @copyright Copyright © 2022 Magento. All rights reserved.
* @author Vyacheslav Shmal
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Result\Page">
<plugin name="pageLayoutDefaultClass" type="Vendor\ModuleName\Plugin\Result\Page"/>
</type>
</config>
And then create the plugin class in Vendor/ModuleName/Plugin/Result/Page.php
<?php
/**
* Page
*
* @copyright Copyright © 2023 Magento. All rights reserved.
* @author Vyacheslav Shmal
*/
namespace Vendor\ModuleName\Plugin\Result;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\View\Result\Page as ResultPage;
class Page
{
/**
* @param ResultPage $subject
* @param ResponseInterface $response
* @return array
*/
public function beforeRenderResult(
ResultPage $subject,
ResponseInterface $response
) : array {
// Apply the updated layout handles classes to the body when using our full width variants
if ($subject->getConfig()->getPageLayout() == 'page-layout-my-layout-file-name') {
$subject->getConfig()->addBodyClass('page-layout-2columns-left');
}
return [$response];
}
}