1

I am trying to replace the customer.login.container on the login page, which can be done through customer_account_login.xml by adding something like:

<referenceContainer name="customer.login.container" remove="true" />

However, I need to set a config condition (similar to ifconfig for blocks), where I will remove this container if a certain config is true, and replace it with another container/blocks. If the config is false, the original page should remain untouched.

I have tried overriding the toHtml method in the login class, but get strange results and it's probably not the best way to do this. Is it possible to do this through the XML files alone? If not, what's the most harmless way to intervene here without removing existing Magento functionality or creating an observer / any kind of action that waits for the original container to load and only then makes changes?

0

It appears to be technically possible, even though this solution is not ideal IMO because it removes the container in a different place than the other layout definitions usually take place, and it feels like a bad hack. I hope someone can give a better answer.

The method is this: it's necessary to override \Magento\Framework\View\Element\AbstractBlock's _toHtml() method. The way to disable the container is through AbstractBlock::unsetElement(). For example:

if ($this->_scopeConfig->getValue('module/section/config', 'website') === 'relevant_value')
{
    $this->getLayout()->unsetElement('customer.login.container');
}
return parent::_toHtml();

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.