Magento 2 Layout XML – Conditionally Show Block

layoutmagento2system-config

<referenceContainer name="header-wrapper">
     <block class="VES\Sociallogin\Block\Buttons" ifconfig="section/group/field/type_multiselect" value="something" as="block.buttons.header" template="Vendor_MOdule::template.phtml" after="-" >
        </block>
</referenceContainer>

Can i do check ifconfig value that saved in system config?

Best Answer

Yes you can but you cannot check a specific value using layout. So for example, you can do the following that checks to make sure the contacts page is enabled;

<block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="contact/contact/enabled" name="contact-us-link"/>

Basically the ifconfig checks for an equivalent of true or false. If you want to check a specific value then you would need to use an observer Magento 2: Remove block depending on a config setting