Skip to content

Allowing a child for Snippets #16852

@zachinglis

Description

@zachinglis

Describe the problem

There have been multiple times where I've wanted to pass HTML to a Snippet during a render call.

The current way to do to this is create a whole new Snippet, then pass it on. Which feels gross when you have 2 or more. I was wondering what the general consensus is? Do you find this an anti-pattern?

I often use Snippets when creating a component would be overkill. Such as reuse within one specific component, but I'd still like to be able to have better control over the content.

Describe the proposed solution

{#snippet row(title: string, content: Snippet)]
   <div>
     <h1>{title</h1>
     {@render content()}
   </div>
{/snippet}

{@render row("Testing", <div>an example</div>)} // Do it on the fly`

or

{#snippet row(title: string)
   <div>
     <h1>{title</h1>
     {@render children}
   </div>
{/snippet}

{#render row('Second Test')} // Use it like you would component's children
   <div>
      Hello!
  </div>
{/render}

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions