Magewire templates conventionally reside in a directory
Usually component and template names match.
For example, a component
My\Module\Magewire\ExampleForm will use a template
If a block with a Magewire view model is not assigned a template, Magewire will default to a template name following this convention.
Inside Magewire component templates, the component instance is available through a
$magewire template variable, hence it is not necessary to call
$block->getData('magewire') and assign the instance to a variable yourself.
Required single root element
A Magewire component template must have a single root element.
If multiple root DOM elements are present, Magewire will not properly update the section of the component after values change.
The following example is correct, because there is only a single
<div> root element:
The following example is WRONG, because there are two root elements:
The following is another example of an invalid component template, because the leading text also counts as a second root node:
Rendering component values
Inside a template, you can interact with any methods and properties of the
You can call any view model method to render its returned value:
There are several ways to read
If you are familiar with Magento backend development, it might be surprising that Magewire provides magic
has methods for properties, but no magic
set method is available.
Instead, use direct assignment