Provide an x-else for conditional rendering #2746
Replies: 5 comments 2 replies
-
We definitely need this feature! |
Beta Was this translation helpful? Give feedback.
-
reminds me about sveltejs promise template syntax... {#await promise}
<span>Loading... please wait</span>
{:then user}
<h1>Hello {user.name} 👋</h1>
{:catch error}
<span>Something went wrong: {error.message} 🤕</span>
{:finally}
<p>done loading</p>
{/await} should have something like that also |
Beta Was this translation helpful? Give feedback.
-
any update ? |
Beta Was this translation helpful? Give feedback.
-
That'd be really nice to have |
Beta Was this translation helpful? Give feedback.
-
I would love to have this feature or a new directive ( <template x-match="option">
<div x-case="A">Option A is active</div>
<div x-case="B">Option B is active</div>
</template> So I dont have to write this ugly code: <template x-if="dark_theme">
<link href="{{ dark_pygments_css }}" rel="stylesheet" />
</template>
<template x-if="!dark_theme">
<link href="{{ light_pygments_css }}" rel="stylesheet" />
</template> |
Beta Was this translation helpful? Give feedback.
-
The thing is,
if-else
has a different meaning than twoif
s.Also, an
if-else
will only evaluate once, twoif
s two times.Using an
if-else
for a conditional rendering can be handy though, React / Vue / Svelte etc. all have it because it is like a syntactic sugar.When extending the conditional rendering with such an
else
statement, it should be considered to also provide anelse-if
.Beta Was this translation helpful? Give feedback.
All reactions