Code Monkey home page Code Monkey logo

Comments (6)

MotionlessTrain avatar MotionlessTrain commented on July 18, 2024 1

This can work too:

{#if snippetHeader}
  {@render snippetHeader()}
{:else}
  myDefaultContent
{/if}

No need for a second snippet name when done like this

from svelte.

Dudek-AMS avatar Dudek-AMS commented on July 18, 2024

snippets can take params and the aim is to remove the markup from the logic, so this is not a good alternative

from svelte.

paoloricciuti avatar paoloricciuti commented on July 18, 2024

snippets can take params and the aim is to remove the markup from the logic, so this is not a good alternative

Wdym by "snippets can take params"? snippetHeader could also take a param in this case.

from svelte.

Dudek-AMS avatar Dudek-AMS commented on July 18, 2024

right from the docs

{#snippet figure({ src, caption, width, height })}
	<figure>
		<img alt={caption} {src} {width} {height} />
		<figcaption>{caption}</figcaption>
	</figure>
{/snippet}

also you gonna lose the possiblity to pass the 'defaultSnippet' to another Component

from svelte.

brunnerh avatar brunnerh commented on July 18, 2024

If you actually need a default snippet to further pass around, you can define it as necessary.
This does not seem all that common of a requirement.

If you have default content in an else branch, you can directly use the variables in scope, the only thing the snippet adds is destructuring, which can be done with @const.

{#if snippetHeader}
  {@render snippetHeader(data)}
{:else}
  {@const { a, b, c } = data}
  ...
{/if}

Do not see an issue with arguments here.

from svelte.

dummdidumm avatar dummdidumm commented on July 18, 2024

All these use cases can be solved with if/else blocks or fallback snippets being applied. We're not going to introduce different syntax for this, therefore closing.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.