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
- 
 check this answer magento.stackexchange.com/a/277066/66058Hiren– Hiren2019年07月10日 04:12:09 +00:00Commented Jul 10, 2019 at 4:12
1 Answer 1
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>
- 
 Thank you for your help. I have not been here since a long time.Dr. Christian Kusche– Dr. Christian Kusche2020年01月26日 13:21:48 +00:00Commented Jan 26, 2020 at 13:21