Description
Within the XML layout, you can reference a block using a <referenceBlock name="foobar">
statement. By manipulating its arguments
(recommended) and actions
(deprecated) you can update the template
property just fine. However, the documentation http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html#set_template mentions you can also use the following syntax:
<referenceBlock name="example" template="example.phtml" />
When I try this, it works just fine. However, when opening up XML layout in PhpStorm, which is setup to respect the XSD of urn:magento:module:View/Layout:etc/page_configuration.xsd
, it is mentioned that the template
parameter is not allowed within a referenceBlock
.
This either means that the documentation is incorrect or that the XSD is incorrect. I would suggest that the XSD is incorrect, because setting the template this way is useful.
Preconditions
I've been seeing this in all of the Magento 2.1 versions I've worked with. However, I also remember this used to work one time as well.
Suggested fix
Within the file Magento_Framework/View/Layout/etc/elements.xsd
there is a definition for blockReferenceType
. Here the definition should include an additional line to allow for an optional argument template
:
<xs:attribute type="xs:boolean" name="template" use="optional"/>