This is my layout file :

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left"
    <update handle="my_custom_layout_1" />
    <update handle="my_custom_layout_2" />

I want to update handle my_custom_layout_2 if value from system configuration is "abc" otherwise, I don't want to update that handle.

How to do that ?

Any help would be appreciated.

  • Hvae you tied using ifconfing as I guess it is not possible to do layout update like that. – Korbin Oct 21 at 12:57
  • @Korbin, We can not use ifconfig for update handle. – Kishan Savaliya Oct 21 at 13:05
  • Ifconfig will not working. Ifconfig only use for boolean value. – Niket Oct 21 at 13:10

You can do that using Controller action

You can use below code

namespace Vendor\Module\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
    protected $resultPageFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
        $this->resultPageFactory = $resultPageFactory;
        return parent::__construct($context);

    public function execute()
        $resultPage = $this->resultPageFactory->create();

        $config = $this->getConfig('test/test/test');

        return $resultPage;

Hope this will help you!

  • Is it any possible way via xml? – Niket Oct 21 at 18:51
  • @Niket, we can add ifconfig condition in block but you need to update handler so you need to follow that using Controller or using Observer only. You can't do that using XML. Hope my answer is helpful to you. – Kishan Savaliya Oct 22 at 1:42
  • Your code is not working. Can you please help me? – Niket Oct 24 at 11:43
  • Yes sure let me know what you did here? – Kishan Savaliya Oct 24 at 11:44
  • 1
    Okay I'll send you one example within hour then I'll send module's link here – Kishan Savaliya Oct 24 at 11:48

You could use a plugin


     * @param \Magento\Framework\View\Result\Layout $subject
     * @return \Magento\Framework\View\Result\Layout
     * @throws \Magento\Framework\Exception\NoSuchEntityException
    public function afterAddDefaultHandle(
        \Magento\Framework\View\Result\Layout $subject
    ) {
        $storeId = $this->storeManager->getStore()->getId();
        if ($this->pageHelper->isEnabled($storeId) && !$this->pageHelper->isDevAllowed($storeId)) {
        return $subject;

See how it's based on config


     * Maintenance page
     * @param null $storeId
     * @return mixed
    public function isEnabled($storeId = null)
        return $this->scopeConfig->getValue(
  • Is it any possible way via xml? – Niket Oct 21 at 18:51
  • You can define defaults in XML. You dont have to have system.xml show options in store configuration – Dominic Xigen Oct 21 at 18:53

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.