Magento 2 : I want to add ifconfig in override block xml

Magento 2 : I want to add ifconfig in override block xml

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 : I want to add ifconfig in override block xml

Magento 2: Overriding Blocks XML with ifconfig

Magento 2 provides a robust way to override blocks using XML files. You asked about overriding the checkout.success block with an ifconfig condition. Let’s dive into this issue and find a solution.

Understanding the Problem

You tried to override the success.phtml file from the vendor\magento\module-checkout\view\frontend directory with your custom file located at app\code\Custom\Module\view\frontend\checkout\success.phtml. Your XML configuration in checkout_onepage_success.xml was correctly set up to use the ifconfig condition. However, when you disabled your module, the default Magento block did not execute as expected.

The ifconfig Condition

The ifconfig condition allows you to conditionalize your layout XML based on a configuration setting. When the configured path evaluates to true (1), the XML inside the ifconfig tag is processed; otherwise, it’s ignored.

In your case:

<referenceBlock name="checkout.success">
    <action method="setTemplate" ifconfig="custom_general/general/active">
        <argument name="template" xsi:type="string">Custom_Module::checkout/success.phtml</argument>
    </action>
</referenceBlock>

The custom_general/general/active path is checked. If the value is 1, your custom template is used; if it’s 0 or not set, Magento uses its default success template.

The Issue: Default Template Not Executing

When you disable your module in the configuration, the custom_general/general/active path is no longer available in the layout XML. This leads to an error because the ifconfig condition cannot find the required configuration path.

The Solution

To resolve this issue, we need to ensure that even when your module is disabled, a default template is always loaded for the checkout.success block. We can achieve this by using two separate action methods in different XML files:

  1. Create a new XML file (e.g., default_onepage_success.xml) and include it in your theme’s layout XML.
  2. In this new XML file, add an action to set the default template for the checkout.success block.

Here’s how you can do it:

In app\code\VendoreName\Module\view\frontend\layout\default_onepage_success.xml:

<referenceBlock name="checkout.success">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Magento_Checkout::success.phtml</argument>
    </action>
</referenceBlock>

Then, include this new XML file in your theme’s layout:

In app\design\frontend\YourTheme\yourtheme\Magento_Theme/layout/default.xml:

<referenceContainer name="before.body.end">
    <block class="Magento\Framework\View\Element\Template" name="default_onepage_success" template="VendoreName_Module::default/onepage/success.phtml"/>
</referenceContainer>

This approach ensures that Magento always loads a default template for the checkout.success block, even when your module is disabled. The ifconfig condition is no longer required in this case.

Conclusion

In Magento 2, it’s essential to handle edge cases like module disablement gracefully. Using separate XML files for default and conditional layout changes ensures that your store remains functional under all conditions.

This approach also demonstrates the power of Magento’s layout system, which allows you to create flexible and maintainable layout configurations. By following these best practices, you can avoid issues like the one you encountered.

Remember to replace VendoreName with your actual module name in the XML files.

Happy coding! For more tips on Magento development, be sure to check out our Magento blog for regular updates and insights.

Magento 2 Checkout Extensions Themes

Our network