wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

Is there anything like 'rt-else'? #148

Closed PierBover closed 8 years ago

PierBover commented 8 years ago

Using rt-if we can render elements based on a condition.

Is there anything like rt-else to render something else if the condition is not met?

nippur72 commented 8 years ago

no, there isn't, I guess because the resulting syntax would be not so intuitive. An hypothetical rt-else would have to refer to its upper sibiling node, which is unusual in HTML.

When I have to write "else branches", I just use an if-not:

<dif rt-if="cond()">then branch</div>
<dif rt-if="!cond()">else branch</div>

if you are concerned about the condition being evaluated twice (in case it's slow etc):

<virtual rt-scope="cond() as c">
   <dif rt-if="c">then branch</div>
   <dif rt-if="!c">else branch</div>
</virtual>
PierBover commented 8 years ago

Thanks for the answer @nippur72

When I have to write "else branches", I just use an if-not

Yes, that's what I ended up doing. It's not so bad for simple stuff.