Svelte template directives

From spences10/skills · View interactive version

Svelte template directives is an AI agent skill from the GitHub repository spences10/skills. Svelte template directive guidance. Use when working with snippets, attachments, dynamic HTML, declaration tags, debugging tags, or global DOM events.

How to use this skill

Skill file

Svelte Template Directives

@attach (Svelte 5.29+)

The reactive alternative to use: actions. Re-runs when dependencies

change, passes through components via spread, supports cleanup functions.

<script>
	import ImageZoom from 'js-image-zoom';

	function useZoom(options) {
		return (element) => {
			new ImageZoom(element, options);
			return () => console.log('cleanup');
		};
	}
</script>

<!-- Re-runs if options changes (use: wouldn't!) -->
<figure {@attach useZoom({ width: 400 })}>
	<img src="photo.jpg" alt="zoomable" />
</figure>

Quick Reference

| Directive | Purpose | Reactive? |

| --------------------------- | ------------------------------ | --------- |

| {@attach} | DOM manipulation, 3rd-party | Yes |

| {@html} | Render raw HTML strings | Yes |

| {@render} | Render snippets | Yes |

| {let ...} / {const ...} | Local declarations in markup | N/A |

| {@debug} | Pause debugger on value change | N/A |

| {#each (key)} | Keyed iteration (always key!) | Yes |

| <svelte:window> | Window event listeners | N/A |

@attach vs use: Actions

| Feature | use: | @attach |

| --------------------- | ------- | ------------------- |

| Re-runs on arg change | No | Yes |

| Composable | Limited | Fully |

| Pass through props | Manual | Auto via spread |

| Convert legacy | N/A | fromAction() |

Reference Files

examples

declaration tags, @debug

Notes

<!--

PROGRESSIVE DISCLOSURE GUIDELINES:

-->

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.