How to use ifconfig in layout xml Magento 2?

How to use ifconfig in layout xml Magento 2?

In Magento 2, we can use ifconfig in layout XML for the block to display or not based on the Magento / Config / Model / Config / Source / Yesno configuration field by using the ifconfig argument.

Basically, it’s a condition in that block, which determines whether the block content is going to be rendered or not.

Syntax :

Here, in the block we have specified ifconfig=”section/group/field“, if the system config returns boolean value true then the block will be rendered only.

Let’s see and understand the below example :

Here in the above example, if the contact form is enabled from the store configuration then only the footer will show the Contact Us link.

Using this approach you can use ifconfig in layout XML to make block dynamic based on store configurations.

You may also like :

How to Get Store Configuration value in Magento 2?

How to get value from env.php in Magento 2?

That’s it for this tutorial, Happy Coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *