Enhance documentation with Svelte examples

Added examples for dynamic tags and comments in Svelte.
pull/18482/head
Scott Wu 2 weeks ago committed by GitHub
parent eae50dfd1c
commit d908b68232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,19 @@ A lowercase tag, like `<div>`, denotes a regular HTML element. A capitalised tag
</div>
```
Svelte safely omits dynamic tags if the resolved property is `null` or `undefined`, but it expects the object path to be valid object.
```svelte
<script>
let Widget = $state(null)
let child = $state({ widget: null })
</script>
<Widget />
<child.widget />
```
## Element attributes
By default, attributes work exactly like their HTML counterparts.
@ -180,12 +193,21 @@ The expression will be stringified and escaped to prevent code injections. If yo
## Comments
You can use HTML comments inside components.
You can use HTML comments inside components and inside tags.
```svelte
<!-- this is a comment! --><h1>Hello world</h1>
```
```svelte
<div
// this is a comment!
data-foo="bar"
>
foo bar
</div>
```
Comments beginning with `svelte-ignore` disable warnings for the next block of markup. Usually, these are accessibility warnings; make sure that you're disabling them for a good reason.
```svelte

Loading…
Cancel
Save