-
-
Notifications
You must be signed in to change notification settings - Fork 364
[TwigComponent] Add documentation about passing blocks to embedded components #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parts are a bit more technically worded than I’d like - and I dropped you an idea on slack, but this is very nice: you chose excellent examples to show off what’s possible. Thanks!
src/TwigComponent/doc/index.rst
Outdated
@@ -832,6 +832,140 @@ The ``with`` data is what's mounted on the component object. | |||
|
|||
Embedded components *cannot* currently be used with LiveComponents. | |||
|
|||
Passing blocks to embedded components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uppercase Blocks, Embedded and Components
src/TwigComponent/doc/index.rst
Outdated
|
||
.. versionadded:: 2.10 | ||
|
||
The `outerBlocks` variable has been added since 2.10. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `outerBlocks` variable has been added since 2.10. | |
The ``outerBlocks`` variable was added in 2.10. |
src/TwigComponent/doc/index.rst
Outdated
{% endcomponent %} | ||
|
||
What if this SuccessAlert component wants to make the content of its nested Alert component configurable? | ||
Well, you can use the special `outerBlocks` variable for those cases. This makes it possible to refer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In rst, unlike markdown, all technical words have 2 “ticks” around them, not just 1
src/TwigComponent/doc/index.rst
Outdated
Look mom, I'm a complex component! | ||
{% endcomponent %} | ||
|
||
Note that to pass a block multiple components down, each component would need to pass it along. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure about this part - it seems obvious enough to me, and the code below REALLY makes this look complex. I vote for mentioning this perhaps, but not showing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're right. Essentially, it was kinda explaining how blocks work, which is not the scope of this documentation.
src/TwigComponent/doc/index.rst
Outdated
{# templates/target.html.twig #} | ||
<div>{% block foo %}default content for foo{% endblock %}</div> | ||
|
||
Context of embedded components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uppercase everything except of
src/TwigComponent/doc/index.rst
Outdated
|
||
Every embedded component can be viewed as another template inside a template, hence the name. | ||
Or in other words, in the other direction, it's as if the embedded component's blocks are copy-pasted | ||
into that component's template. This has a few interesting consequences. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
into the target component’s template
src/TwigComponent/doc/index.rst
Outdated
Or in other words, in the other direction, it's as if the embedded component's blocks are copy-pasted | ||
into that component's template. This has a few interesting consequences. | ||
|
||
First of all, although `this` is referring to the component of the template into which an (embedded) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, although this
refers to…
src/TwigComponent/doc/index.rst
Outdated
|
||
First of all, although `this` is referring to the component of the template into which an (embedded) | ||
component is nested, *INSIDE* an embedded component it is referring to the *embedded* component, | ||
*NOT* the component into which it's being nested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording on this is really tricky: nested vs embedded. Maybe say less and let the code do the talking.
src/TwigComponent/doc/index.rst
Outdated
|
||
.. code-block:: twig | ||
|
||
{# templates/successAlert.html.twig #} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SuccessAlert.html.twig - I think that’s in a few places.
Hey! I just did a quick proof and edit of the docs so far - a team effort to explain these important concepts on a simple way. I've tried to remove the wording "embedded component". Even I mix up "embedded" and "nested" in my mind. It's not as succinct, but saying "when you pass a block to a component" instead of "when you render an embedded component" I think is much more clear. |
Love it. Indeed I also always have to think twice to correctly separate nested vs embedded components. It took a while to get this terminology right in my head, but it will take perhaps equally long to stop referring to them as embedded components :-) |
I think so yes. So we may sometimes still use that term - but let's see if we can avoid it for the "outside" world :) |
@weaverryan As discussed on Slack, I also allowed references to outer blocks from with a regular (non-nested) component. |
10ecefd
to
111ac3a
Compare
2a2accb
to
ae5a458
Compare
Thanks Bart! |
This PR was merged into the 2.x branch. Discussion ---------- Fix typo in outerBlocks doc | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | | License | MIT I noticed the recently merged doc from #985 had a small typo in one of the snippets. Commits ------- 1f45fad Fix typo in outerBlocks doc
This adds documentation of the feature added in #920