Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create an intermediate variable for multiple use in {#each} block? #4614

Closed
angryziber opened this issue Mar 30, 2020 · 2 comments
Closed

Comments

@angryziber
Copy link

angryziber commented Mar 30, 2020

Sometimes you need to calculate/retrieve something while iterating with {#each}.
It would be nice to be able to reuse this calculation, if it needs to be used multiple times, e.g.:

{#each sections as section}
  {#with url = '/path/to/' + section}
    <a href={url}>{url}</a>
  {/with}
{/each}

Is there something in current svelte that would enable this? Or can someting like this {#with} added?

@angryziber
Copy link
Author

angryziber commented Mar 30, 2020

I discovered that a solution can be hacked using an {#if}, but a proper one would be nice:

<script>let url</script>

{#each sections as section}
  {#if url = '/path/to/' + section}
    <a href={url}>{url}</a>
  {/if}
{/each}

@Conduitry
Copy link
Member

Basically a duplicate of #1521. See also #4601 - there's an open PR for {#with}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants