When building out an example side by side component for experience builder in #3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree" I encountered an error about missing definitions for slots I was trying to populate in an embedded component. My attempt at embedding the two_column component in the side by side throws the error:
Twig\Error\SyntaxError: An exception has been thrown during the compilation of a template ("We found an unexpected slot that is not declared: [column_one, column_two]. Declare them in "side_by_side.component.yml"."). in Twig\Environment->compileSource() (line 2 of experience_builder_example_components/components/compound/side_by_side/side_by_side.twig).
<div{{ attributes.addClass("bg-"~background) }}>
........
{% embed 'experience_builder_example_components:two_column' %}
{% block column_one %}
{% if media_position == "left" %}
{{ media }}
{% else %}
{{ comp_content }}
{% endif %}
{% endblock %}
{% block column_two %}
{% if media_position == "left" %}
{{ comp_content }}
{% else %}
{{ media }}
{% endif %}
{% endblock %}
{% endembed %}
</div>
This is unexpected because the slots column_one and column_two are defined correctly for the two_column component which means they shouldn't need to be defined in the side_by_side component.
To reproduce this you can install the experience_builder_example_components submodule that is introduced in the MR for #3446722: Introduce an example set of representative SDC components; transition from "component list" to "component tree". The module automatically places the side_by_side component on the front page of the site which will error out due to this slots issue
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 3446933--21--embeds-in-slots.patch | 16.87 KB | e0ipso |
Issue fork drupal-3446933
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
e0ipsoI am able to reproduce this.
We will also need to consider
extend, no justembed.Comment #3
lauriiiComment #5
e0ipsoTest only patch is failing with the expected error: https://git.drupalcode.org/issue/drupal-3446933/-/jobs/1730262#L45
The pipeline with the fix is green.
This is ready to review.
Comment #6
penyaskitoI can reproduce this issue with the Storybook module integration, the patch fixes it, it includes tests, and test-only run is failing.
Code looks good.
The only thing I could suggest is a test with two elements nested instead of one, to check that those are traversed from bottom to top, but that might actually be testing twig itself and not our code.
Comment #7
alexpott#2 says we need to consider extend and not just embed but we only add test coverage for embed. Have we considered extend? Should we add a test for it?
Comment #8
e0ipso@alexpott while working on an example with
extendsI realized that the trick to forward block contents will not work on extended templates. This is not related to SDC, but a Twig limitation.In the example above there is no scope for
extend-example.twigto grab the contents of the blocknested_slot.Since we are extending another template it does not make sense to introduce a new slot/block, you just use the blocks defined by the parent instead. Therefore I think now, that I was wrong in #2 to suggest that we need to support
extends.Back to RTBC based on the above.
Comment #9
e0ipsoPlease ignore my comment in #8 🤦. I was conflating two different issues here.
To recap this issue proves that we can:
blocks from the parent to the children.Comment #10
e0ipsoIf you are curious about my confusion in #8, I was trying to write a test for 4, before I wrote one for 2:
4. Have embed within extends and forward blocks from the parent to the children.
However, that is not valid Twig. And that is what a I was realizing in #8.
The commit above adds test coverage for extends, and we should be good now.
Comment #11
lauriiiComment #12
smustgrave commentedCan the MR be updated for 11.x vs 11.0.x please
Also can issue summary be updated using the standard template, wasn't entirely sure what the solution is without having to look at the code.
Comment #13
quietone commentedFixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies. Also, 10.2 is in security mode now.
Comment #14
alemadleiMerge requests works for me on D11.0.5
Comment #15
e0ipsoAdding a patch for the MR as of #9, so we can add it to composer patches.
Comment #16
e0ipsoComment #17
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #18
penyaskitoRebased
Comment #19
penyaskitoI rebased with cherry-pick + fixed the test components slots adding title. Trivial changes so I feel eligible to get this back to RTBC.
Comment #20
smustgrave commentedClosed https://www.drupal.org/project/drupal/issues/3464719 as a duplicate
Comment #21
e0ipsoUploaded a patch file for composer.
Comment #22
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #25
daniel.pernold commentedPatches or MRs do not apply on Drupal 10.6.10.
Comment #26
penyaskitoRebased with main.
Comment #27
smustgrave commentedCan we cleanup the IS some?