Skip to main content
The createRawSnippet() function creates a snippet programmatically from a render function. This is useful for library authors or when you need to generate snippets dynamically.

Import

Signature

Parameters

fn
function
required
A function that receives the snippet parameters and returns an object with render and optional setup methods

Returns

Snippet
Snippet<Params>
A snippet that can be rendered with {@render}

Usage

Basic snippet

With parameters

With setup and cleanup

Dynamic rendering

Library wrapper

Notes

  • The render function is called every time the snippet is rendered
  • The setup function is called once after the HTML is inserted into the DOM
  • HTML is inserted as raw HTML (not sanitized)
  • Use with caution - improper use can lead to XSS vulnerabilities
  • Primarily intended for library authors and advanced use cases
  • Regular snippets ({#snippet}) are preferred for normal application code

See also

  • Snippets - Declarative snippet syntax
  • Slots - Content projection patterns