magento2: Add support for ifconfig to referenceBlock
Description (*)
If you are defining a new block, you can use ifconfig
to only enable the block when a backend setting is true.
This is not supported for referenceBlock. I created a module where I am modifiying the block contactForm
from the module Module_Contact
by replacing the template with my own.
I also created a setting for my extension where I can toggle it on or off.
The template should only get overriden, if the setting is set to true.
So I added ifconfig="company_contact/general/enabled"
to referenceBlock
<referenceBlock name="contactForm"
ifconfig="company_contact/general/enabled"
template="Company_Contact::form.phtml" />
But I get Element ‘referenceBlock’, attribute ‘ifconfig’: The attribute ‘ifconfig’ is not allowed., and therefor what I try is not possible.
Expected behavior (*)
It should not throw an error.
Benefits
More ways to customize magento
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 22
- Comments: 15
Would be great, in fact!
We have every reason to implement this as a new feature. Please accept and work on this one.
Really good feature
This would be really helpful!
I’d love to have this feature as well. Right now I implement this functionality with custom block in layout and rendering the original block as a child within the new block. This way ifconfig is usable, but it’s a pretty ugly way to do it.
@Eddcapone yes this makes perfect sense. i too arrived at the same position as yours. can’t find a way to enable/disable module without if-config.i overrode .html and .js files from module_checkout
This is still a good idea in my oppinion.
Would be great to have this feature
This is the most intuitive approach to conditionally removing existing blocks from a custom module or theme.