4

Is it possible to control the layout using URL params? For example, I would like to be able to remove the sidebar block by adding &sidebar=no to the URL. It would be great if I can do this in the layout XML itself -- something like this:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <action method="remove" ifrequestparam="sidebar" condition="true">
            <referenceContainer name="sidebar.main"/>
        </action>
    </body>
</page>

I know this is not possible right now, but what is the next simplest method to achieve something like this?

2

I believe you get an idea from this, we can able to remove block programatically.

so you can try in your controller like

if($this->request->getParam('sidebar')=='no')
{
    $layout = $this->getLayout();
    $block = $layout->getBlock('Block Name'); // block name
    $layout->unsetElement('Block Name');
}

I found only remove block programatically, may be chances is there to remove container but I'm not sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.