Skip to content

Commit 446f1cf

Browse files
committed
update slot tutorial content to snippets
1 parent 9ba7bf7 commit 446f1cf

File tree

15 files changed

+84
-53
lines changed

15 files changed

+84
-53
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
<script>
2+
const { children } = $props();
3+
</script>
4+
15
<div class="card">
2-
<slot />
6+
{@render children()}
37
</div>
48

59
<style>

apps/svelte.dev/content/tutorial/02-advanced-svelte/07-composition/01-slots/index.md renamed to apps/svelte.dev/content/tutorial/02-advanced-svelte/07-composition/01-snippets/index.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Slots
2+
title: Snippets
33
---
44

55
Just like elements can have children...
@@ -11,12 +11,15 @@ Just like elements can have children...
1111
</div>
1212
```
1313

14-
...so can components. Before a component can accept children, though, it needs to know where to put them. We do this with the `<slot>` element. Put this inside `Card.svelte`:
14+
...so can components. Before a component can accept children, though, it needs to know where to put them. We do this with the `children` prop and the render tag `{@render children()}` – which is a bit like a function call. Put this inside `Card.svelte`:
1515

1616
```svelte
1717
/// file: Card.svelte
18+
+++<script>+++
19+
+++ const { children } = $props();+++
20+
+++</script>+++
1821
<div class="card">
19-
+++<slot></slot>+++
22+
+++{@render children()}+++
2023
</div>
2124
```
2225

apps/svelte.dev/content/tutorial/02-advanced-svelte/07-composition/02-named-slots/+assets/app-a/src/lib/App.svelte

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script>
2+
import Card from './Card.svelte';
3+
</script>
4+
5+
<main>
6+
<Card>
7+
<span>Patrick BATEMAN</span>
8+
<span>Vice President</span>
9+
10+
{#snippet telephone()}
11+
<span>212 555 6342</span>
12+
{/snippet}
13+
14+
{#snippet company()}
15+
<span>
16+
Pierce &amp; Pierce
17+
<small>Mergers and Aquisitions</small>
18+
</span>
19+
{/snippet}
20+
21+
{#snippet address()}
22+
<span>358 Exchange Place, New York, N.Y. 10099 fax 212 555 6390 telex 10 4534</span>
23+
{/snippet}
24+
</Card>
25+
</main>
26+
27+
<style>
28+
main {
29+
display: grid;
30+
place-items: center;
31+
height: 100%;
32+
background: url(./wood.svg);
33+
}
34+
</style>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
<script>
2+
const { children } = $props();
3+
</script>
4+
15
<div class="card">
2-
<slot />
6+
{@render children()}
37
</div>
48

59
<style>

0 commit comments

Comments
 (0)