0

The standard layout of my categories is 2-columns-left so that the layered navigation is visible in my shop. What I want is, to use the same categories to display content.

This is an example for my shop link: products/chemicals.html If I click this link my products are shown in my list.phtml

This is an example for my "cms" link: products/chemicals.html?cms_id=123 If I click this link my "cms" content is displayed in my list.phtml

What I want now, is to display my content without the left sidebar. By CSS I can set the sidebar display:none, that works, but the page loads my products.

I would prefer to change the page layout when I call my "cms" category page.

Any idea?

Christian

poojan sharma
1,5561 gold badge11 silver badges16 bronze badges
asked Jul 10, 2019 at 2:52
1

1 Answer 1

0

Create a frontend/events.xml

<event name="layout_load_before">
 <observer name="test_layout_change" instance="Tets\Module\Observer\AddUpdateHandlesObserver" />
</event>

Create class for Observer.

<?php
namespace Test\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Event\Observer;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Request\Http;
/**
 * Class AddUpdateHandlesObserver
 * @package Test\Module\Observer
 */
class AddUpdateHandlesObserver implements ObserverInterface
{
/**
 * @var Http
 */
protected $request;
/**
 * @var StoreManagerInterface
 */
protected $storeManager;
/**
 * @var ProductRepositoryInterface
 */
protected $productRepository;
/**
 * AddUpdateHandlesObserver constructor.
 * @param Http $request Request
 * @param StoreManagerInterface $storeManager StoreManager
 * @param ProductRepositoryInterface $productRepository ProductRepository
 */
public function __construct(
 Http $request,
 StoreManagerInterface $storeManager,
 ProductRepositoryInterface $productRepository
) {
 $this->request = $request;
 $this->storeManager = $storeManager;
 $this->productRepository = $productRepository;
}//end __construct()
/**
 * @param Observer $observer Observer
 * @return $this|bool|void
 */
public function execute(Observer $observer)
{
 $layout = $observer->getData('layout');
 if ({ur_conditon}) {
 $layout->getUpdate()->addHandle('layout_file_name');
 }
 return $this;
}//end execute()
}//end class

Create layout_file_name.xml Inside extend the parent_layout file and remove the respective sidebar from the xml file.

<update handle="catalog_category_view" />
<body>
<referenceBlock name="block_name_which_you_want_remove" remove="true" />
</body>
Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
answered Jul 10, 2019 at 4:02
1
  • Thank you for your help. I have not been here since a long time. Commented Jan 26, 2020 at 13:21

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.