diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 497396af30..bc82e7b8ae 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -101,27 +101,7 @@ Text can also contain JavaScript expressions: ``` -### HTML expressions - -```sv -{@html expression} -``` - ---- - -In a text expression, characters like `<` and `>` are escaped. With HTML expressions, they're not. - -> Svelte does not sanitize expressions before injecting HTML. If the data comes from an untrusted source, you must sanitize it, or you are exposing your users to an XSS vulnerability. - -```html -
-

{post.title}

- {@html post.content} -
-``` - - -### If blocks +### `{#if ...}` ```sv {#if expression}...{/if} @@ -158,7 +138,7 @@ Additional conditions can be added with `{:else if expression}`, optionally endi ``` -### Each blocks +### `{#each ...}` ```sv {#each expression as name}...{/each} @@ -229,7 +209,7 @@ An each block can also have an `{:else}` clause, which is rendered if the list i ``` -### Await blocks +### `{#await ...}` ```sv {#await expression}...{:then name}...{:catch name}...{/await} @@ -283,7 +263,77 @@ If you don't care about the pending state, you can also omit the initial block. ``` -### DOM events (on:eventname) +### `{@html ...}` + +```sv +{@html expression} +``` + +--- + +In a text expression, characters like `<` and `>` are escaped. With HTML expressions, they're not. + +> Svelte does not sanitize expressions before injecting HTML. If the data comes from an untrusted source, you must sanitize it, or you are exposing your users to an XSS vulnerability. + +```html +
+

{post.title}

+ {@html post.content} +
+``` + + +### `{@debug ...}` + +```sv +{@debug} +``` +```sv +{@debug var1, var2, ..., varN} +``` + +--- + +The `{@debug ...}` tag offers an alternative to `console.log(...)`. It logs the values of specific variables whenever they change, and pauses code execution if you have devtools open. + +It accepts a comma-separated list of variable names (not arbitrary expressions). + +```html + + +{@debug user} + +

Hello {user.firstname}!

+``` + +--- + +`{@debug ...}` accepts a comma-separated list of variable names (not arbitrary expressions). + +```html + +{@debug user} +{@debug user1, user2, user3} + + +{@debug user.firstname} +{@debug myArray[0]} +{@debug !isReady} +{@debug typeof user === 'object'} +``` + +The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when *any* state changes, as opposed to the specified variables. + + + +### Element directives + +#### on:*event* ```sv on:eventname={handler} @@ -370,29 +420,7 @@ It's possible to have multiple event listeners for the same event: ``` -### Component events (on:eventname) - -```sv -on:eventname={handler} -``` - ---- - -Components can emit events using [createEventDispatcher](docs#createEventDispatcher), or by forwarding DOM events. Listening for component events looks the same as listening for DOM events: - -```html - -``` - ---- - -As with DOM events, if the `on:` directive is used without a value, the component will *forward* the event, meaning that a consumer of the component can listen for it. - -```html - -``` - -### Element bindings (bind:property) +#### bind:*name* ```sv bind:property={variable} @@ -436,7 +464,7 @@ Numeric input values are coerced; even though `input.value` is a string as far a ``` -#### Binding related elements (bind:group) +#### `bind:group` --- @@ -460,6 +488,28 @@ Inputs that work together can use `bind:group`. ``` +#### `bind:this` (elements) + +--- + +To get a reference to a DOM node, use `bind:this`. + +```html + + + +``` + + #### Binding `