1

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!

Abhishek Panchal
4,9643 gold badges22 silver badges39 bronze badges
asked Jan 15, 2019 at 21:59
6
  • can you please share your layout file code? Commented 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. Commented Jan 17, 2019 at 22:34
  • Can you provide anymore insight to accomplish this? @AliEjaz Commented Jan 20, 2019 at 0:36
  • @BrandonIrwin Did you get solution? I had face same issue. Commented 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. Commented Sep 21, 2020 at 15:04

2 Answers 2

0

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>
answered Jan 15, 2019 at 22:08
2
  • So when i do this my page appears blank should it at least show something? Commented Jan 16, 2019 at 14:00
  • it is missing </layout> Commented Nov 24, 2020 at 23:01
0

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];
 }
}
answered Sep 19, 2023 at 20:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.