Conditionally show block in layout XML
-
10-12-2020 - |
Question
<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?
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange