sw-block
WARNING
Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).
The extension point. Globally registered, so you write the tag without importing anything. Which prop you pass decides what it does.
| Prop | Type | Meaning |
|---|---|---|
name | string | Declares an extension point. Its children are the default content |
extends | string | Contributes to the extension point of that name. Renders nothing where it stands |
Write name (base components only) or extends (overrides only) as a static attribute and nothing else. The component has other props - your editor may offer them - and they are internal. The build rejects any other attribute or directive on the tag, including class, v-if, a bound :extends, data, v-bind and an authored #default.
Declaring an extension point
<sw-block name="swag_greeting_card_body">
<p>Default content</p>
</sw-block>With nothing registered against the name, this renders as though the wrapper were not there.
Contributing to one
<sw-block extends="swag_greeting_card_body">
<sw-block-parent />
<p>Mine, underneath</p>
</sw-block>The target block is replaced by what goes inside. To keep what was there, render sw-block-parent.
An <sw-block extends> belongs at the root of an override's template and cannot be nested inside another element. Where it sits does not affect where its content renders: it registers the content, and the matching <sw-block name> renders it.
Names
Block names are strings and nothing validates them, so a typo silently matches nothing. They must be unique per component. The convention is an owner prefix and then the path through the component, in snake_case: core uses sw_, a plugin uses its own.
sw_product_detail_base_price_form
swag_greeting_card_bodyBindings in block content
Your override's bindings are available inside its <sw-block extends> content and read like any other Vue template binding. Mutating one from the template - @click="counter++" - is not supported; wrap the mutation in a function and call that instead.
Order, when several extensions meet
Native <sw-block extends> contributions render in registration order, and all of them render after a TwigJS override of the same block. A legacy override is therefore always the parent of a native one, whichever order the plugins load in.