-
|
I'm working with components that use
<div id="{{ id }}" class="parent" {{ attrs }}>
{{ slot }}
</div>
<div data-id="{{ id }}" class="child" {{ attrs }}>
{{ slot }}
</div>
<c-parent id="foo-id">
<c-child>
Some text
</c-child>
</c-parent>In the rendered output, <div id="foo-id" class="parent">
<div data-id="" class="child">
Some text
</div>
</div>One option I can do is wrap with {% with id="foo-id" %}
<!-- The {{ id }} would actually live in parent.html in this case... -->
<div id="{{ id }}" class="parent">
<div data-id="" class="child">
Some text
</div>
</div>
{% endwith %}There's been some discussion around passing data, and while I was going to chime in, I think this ask is slightly different. Here's what I would consider related issues: Is there a way to have parent For extra context, we're trying to move components from Preline/Tailwind to Cotton, and their plugins use Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
Hi,
This worked for me; in your child component attrs = {{ attrs }}.
…On Thu, 27 Mar 2025 at 3:32 AM, Miguel ***@***.***> wrote:
I'm working with components that use {{ slot }} to render children, and
I’ve run into a context propagation issue. Here's a simplified example:
cotton/parent.html
<div id="{{ id }}" class="parent" {{ attrs }}>
{{ slot }}
</div>
cotton/child.html
<div data-id="{{ id }}" class="child" {{ attrs }}>
{{ slot }}
</div>
app/view.html
<c-parent id="foo-id">
<c-child>
Some text
</c-child>
</c-parent>
In the rendered output, {{ id }} inside child.html is empty:
<div id="foo-id" class="parent">
<div data-id="" class="child">
Some text
</div></div>
One option I can do is wrap with {% with %}, but it's ugly:
{% with id="foo-id" %}
<!-- The {{ id }} would actually live in parent.html in this case... -->
<div id="{{ id }}" class="parent">
<div data-id="" class="child">
Some text
</div>
</div>{% endwith %}
There's been some discussion around passing data, and while I was going to
chime in, I think this ask is *slightly* different. Here's what I would
consider related issues:
- #192 <#192>
- #224 <#224>
Is there a way to have parent attr / c-vars to pass into children
components? I did try setting COTTON_ENABLE_CONTEXT_ISOLATION = False as
a long shot, but saw the same results.
For extra content, we're trying to move components from Preline/Tailwind
to Cotton, and their plugins use data-* attributes to "link" elements
together (eg, a <button> opens a <modal>), so passing a selector down the
stack would be extremely beneficial.
Thank you!
—
Reply to this email directly, view it on GitHub
<#272>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AX4PGOCU5QEUMXQ4U6FFUR32WNIJNAVCNFSM6AAAAABZ3XOO6KVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZYGEZTIMJRGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Released in 2.1.0 |
Beta Was this translation helpful? Give feedback.
Released in 2.1.0