Outer Scope Blocks #2837
Unanswered
Phil23
asked this question in
Questions & Answers
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks,
We are currently evaluating using Twig UX components for the standard storefront of shopware. One important aspect for us is the extendability of shopware for our ecosystem.
One issue that we encountered so far is the mix of block scopes that is introduced when using components. We understand that using the block syntax for overriding default content within a component seems logical, but when using these components in a template that should also still be extendable, it limits the way you can access the actual content of the template. Especially when you make use of several nested components.
Example:
You have a template, let's call it
page/example.html.twig
, which can be extended and has some blocks with content in it. Within those blocks you use a bunch of Twig components.If we want to make the navigation extendable, so that, for example, new items could be added, it is not possible to define blocks in the scope of
page/example.html.twig
because starting with<twig:nav>
the scope changes to the inner of the nav component.The only workaround we found so far is to define the inner content via a variable using
set
, but this makes the whole markup very messy, especially if you have several nesting levels.Maybe we are missing something here, so if you know of a better solution, we are more than happy to hear about it. We already worked through the documentation like Inheritance & Forwarding "Outer Blocks", but it seems there is no concept for defining outer scope blocks within component content.
Why not slots?
I know Twig already has the block system and using this syntax seems logical on first sight, but it is not quite the same as the concept of slots known from other famous component frameworks, or? Wouldn't it be better to have a separate syntax like
{% slot %}
to slot content into a component, so that the scopes aren't mixed up with outer page blocks?Beta Was this translation helpful? Give feedback.
All reactions