Skip to content

Commit eca0caa

Browse files
committed
add some docs
1 parent 811843b commit eca0caa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

documentation/docs/03-template-syntax/06-snippet.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ We can tighten things up further by declaring a generic, so that `data` and `row
246246
</script>
247247
```
248248

249+
## Exporting snippets
250+
251+
Snippets declared at the top level of a `.svelte` file can be exported from a `<script module>` for use in other components, provided they don't reference any declarations in a non-module `<script>` (whether directly or indirectly, via other snippets) ([demo](/playground/untitled#H4sIAAAAAAAAE3WPwY7CMAxEf8UyB1hRgdhjl13Bga8gHFJipEqtGyUGFUX5dxJUtEB3b9bYM_MckHVLWOKut50TMuC5tpbEY4GnuiGP5T6gXG0-ykLSB8vW2oW_UCNZq7Snv_Rjx0Kc4kpc-6OrrfwoVlK3uQ4CaGMgwsl1LUwXy0f54J9-KV4vf20cNo7YkMu22aqAz4-oOLUI9YKluDPF4h_at-hX5PFyzA1tZ84N3fGpf8YfUU6GvDumLqDKmEqCjjCHUEX4hqDTWCU5PJ6Or38c4g1cPu9tnAEAAA==)):
252+
253+
```svelte
254+
<script module>
255+
export { add };
256+
</script>
257+
258+
{#snippet add(a, b)}
259+
{a} + {b} = {a + b}
260+
{/snippet}
261+
```
262+
249263
## Programmatic snippets
250264

251265
Snippets can be created programmatically with the [`createRawSnippet`](svelte#createRawSnippet) API. This is intended for advanced use cases.

0 commit comments

Comments
 (0)