You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/content/docs/03-template-syntax.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1600,22 +1600,26 @@ Note that explicitly passing in an empty named slot will add that slot's name to
1600
1600
1601
1601
---
1602
1602
1603
-
Slots can be rendered zero or more times and can pass values *back* to the parent using props. The parent exposes the values to the slot template using the `let:` directive.
1603
+
Slots can be rendered zero or more times.
1604
1604
1605
+
The `let:` directive gives a slot template access to variables defined in the component that uses them.
1605
1606
The usual shorthand rules apply — `let:item` is equivalent to `let:item={item}`, and `<slot {item}>` is equivalent to `<slot item={item}>`.
1606
1607
1607
1608
```sv
1608
1609
<!-- FancyList.svelte -->
1610
+
<!-- This component passes data to its child slot using the `itemData` prop -->
1609
1611
<ul>
1610
1612
{#each items as item}
1611
1613
<li class="fancy">
1612
-
<slot prop={item}></slot>
1614
+
<slot itemData={item}></slot>
1613
1615
</li>
1614
1616
{/each}
1615
1617
</ul>
1616
1618
1617
1619
<!-- App.svelte -->
1618
-
<FancyList {items} let:prop={thing}>
1620
+
<!-- the `let:itemData={thing}` directive makes the value that `FancyList` pases as the `itemData` prop
1621
+
available to the slot template as the `thing` variable -->
0 commit comments