mcpField
S
svelte-template-directives

svelte-template-directives

github.com/spences10Development1697 installsUpdated 16w ago
Repository

About svelte-template-directives

svelte-template-directives は Svelte のテンプレートディレクティブをまとめたリファレンススキルです。特に Svelte 5.29 以降のアタッチメントを扱い、リアクティブな DOM 操作や各種テンプレート機能の選択を支援します。

Key features

  1. 01@attachの利用パターン
  2. 02ディレクティブ用途の早見表
  3. 03use:アクションとの比較
  4. 04描画タグとデバッグタグの案内
  5. 05key付きeachブロックの案内

Use cases

  1. 01リアクティブなDOM動作の適用
  2. 02@attachとuse:の選択
  3. 03スニペットやHTML文字列の描画
  4. 04マークアップ宣言や反復処理の確認

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/spences10/skills --skill svelte-template-directives

After installing, type/svelte-template-directivesin Claude Code to confirm it loaded.

Bundled filesreferences/attach-patterns.mdreferences/other-directives.md

Details

From the project README

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

DirectivePurposeReactive?
{@attach}DOM manipulation, 3rd-partyYes
{@html}Render raw HTML stringsYes
{@render}Render snippetsYes
{let ...} / {const ...}Local declarations in markupN/A
{@debug}Pause debugger on value changeN/A
{#each (key)}Keyed iteration (always key!)Yes
<svelte:window>Window event listenersN/A

@attach vs use: Actions

Featureuse:@attach
Re-runs on arg changeNoYes
ComposableLimitedFully
Pass through propsManualAuto via spread
Convert legacyN/AfromAction()

Reference Files

Notes

  • @attach requires Svelte 5.29+
  • Use fromAction from svelte/attachments to convert legacy actions
  • Attachments pass through wrapper components when you spread props
  • Always use keyed each blocks — never use index as key
  • Use <svelte:window>/<svelte:document> for global events, not $effect
  • Use {const ...} / {let ...} declaration tags for local markup variables; {@const ...} is legacy syntax.
  • Last verified: 2026-05-31

Comments

Markdown supported