Conditionally hide or show a block in Magento 2

Magento 2, Layout XML, Quick Tip

Somehow i only found about this little gem only recently. In your layout xml you can use the ifconfig parameter to hide or show block depending on your configuration. It works as following:

<block class="<VENDOR><MODULE>BlockMyBlockClass" ifconfig="vendor_module/group/configuration_option" name="my-block" />

Now when you make sure the config path vendor_module/group/configuration_option exists, Magento will check the value for you. If it is true-ish you block will be shown, if not it will hide the block. (ad)

Do you want your Magento store to be more reliable? Tired of things that suddenly break the checkout process without anyone noticing? You can hire my services to kickstart End-2-End testing for your Magento store. This way you know for sure that your store is behaving as expected before releasing that new feature or that update.

View for more information.


I tried to find documentation about this, but on the Magento devdocs website this keyword is not found. I have found some usages in the core though so my guess is that it's safe to use:

Want to respond?