Skip to content
Back to skills

Svelte Template Directives

ASecurity

Svelte template directives ({@attach}, {@html}, {@render}, {@const}, {@debug}). Use for DOM manipulation, third-party libs, tooltips, canvas, dynamic HTML. @attach replaces use: actions.

  • 91 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 7, 2026
developmentreact

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned February 12, 2026

npx -y skills add spences10/svelte-skills-kit --skill svelte-template-directives --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Svelte Template Directives?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Svelte Template Directives
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/spences10-svelte-template-directives/badge)](https://www.skillsdirectory.com/skills/spences10-svelte-template-directives)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: svelte-template-directives
# prettier-ignore
description: Svelte template directives ({@attach}, {@html}, {@render}, {@const}, {@debug}). Use for DOM manipulation, third-party libs, tooltips, canvas, dynamic HTML. @attach replaces use: actions.
---

# 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.

```svelte
<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       |
| `{@const}`  | Local constants in blocks      | N/A       |
| `{@debug}`  | Pause debugger on value change | 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

- [attach-patterns.md](references/attach-patterns.md) - Real-world @attach
  examples
- [other-directives.md](references/other-directives.md) - @html, @render,
  @const, @debug

## Notes

- `@attach` requires Svelte 5.29+
- Use `fromAction` from `svelte/attachments` to convert legacy actions
- Attachments pass through wrapper components when you spread props
- **Last verified:** 2025-01-13

<!--
PROGRESSIVE DISCLOSURE GUIDELINES:
- Keep this file ~50 lines total (max ~150 lines)
- Use 1-2 code blocks only (recommend 1)
- Keep description <200 chars for Level 1 efficiency
- Move detailed docs to references/ for Level 3 loading
- This is Level 2 - quick reference ONLY, not a manual
-->

Files in this skill

  • SKILL.md2.3 KB
  • references/attach-patterns.md6.9 KB
  • references/other-directives.md2.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.