1

I want to remove block product.info.addtocart from layout depends on some conditions

  • 1
    We need more information. – St3phan Feb 12 at 13:16
1

You can use ifconfig on block

<block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />

Or you can use helper:

<block name="product.info.addtocart" class="...">
    <action method="setTemplate">
        <argument name="template" xsi:type="helper" helper=“Vendorname\Modulename\Helper\Data::method”>
            <param name="name">Vendorname_Modulename::data/template.phtml</param>
        </argument>
    </action>
</block>

The result in both cases it must to be boolean.

If you want to use in other cases, we need more details.

2

You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.

e.g)

if(here your condition)
{
   $layout = $this->getLayout();
   $layout->unsetElement('product.info.addtocart'); //block name
}

I hope it helps you.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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