The question:
When I try to login in to the frontend, as a customer, I get this error:
Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'referenceBlock', attribute 'ifconfig': The attribute 'ifconfig' is not allowed.
Line: 1052
I’ve read about other people running into the same issue here, with the solution being this.
I’ve never worked with reference blocks so I am unsure if they mean that I need to edit any of the Magento files or is the problem in my extensions?
EDIT
Found this in one of my extension layout files:
<referenceBlock name="customer_account_dashboard_top" ifconfig="cancelorder/general/active" template="CancelOrder::recent.phtml">
Could this be whats causing the error?
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
Yes that’s most probably it.
This is the intended behavior:
You can use ifconfig
attributes only on block
, ui_component
, action
.
referenceBlock
does not allow this attribute.
The xsd
section that describes referenceBlock
can be found in vendor/magento/framework/View/Layout/etc/elements.xsd
.
<xs:complexType name="blockReferenceType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="action" type="actionType" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>
Argument name must be unique in scope of action.
</xs:documentation>
</xs:annotation>
<xs:key name="blockReferenceActionArgumentName">
<xs:selector xpath="argument"></xs:selector>
<xs:field xpath="@name"></xs:field>
</xs:key>
</xs:element>
<xs:element ref="arguments" minOccurs="0" maxOccurs="1"/>
<xs:element ref="block" minOccurs="0"/>
<xs:element name="container" type="containerType" minOccurs="0"/>
<xs:element ref="referenceBlock" minOccurs="0" />
<xs:element ref="referenceContainer" minOccurs="0"/>
<xs:element ref="uiComponent" minOccurs="0" />
</xs:choice>
<xs:attribute type="elementNameType" name="name" use="required"/>
<xs:attribute type="xs:string" name="template" use="optional"/>
<xs:attribute type="xs:boolean" name="display" default="true" use="optional"/>
<xs:attribute type="xs:boolean" name="remove" use="optional"/>
</xs:complexType>
Nothing about ifconfig
in there.
You can try a different approach to solve your issue.
I assume that you are using <referenceBlock name="customer_account_dashboard_top"
to add a block or execute an action on the specified block.
You can add the ifconfig
attribute on your block or action tags.
<referenceBlock name="customer_account_dashboard_top">
<action method="setTemplate" ifconfig="cancelorder/general/active">
<argument name="setTemplate" xsi:type="string">CancelOrder::recent.phtml</argument>
</action>
<!-- or -->
<block class="..." ifconfig="cancelorder/general/active">...</block>
</referenceBlock>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0