Conditionals
Conditionals let you mount / unmount dom and components based on a condition. For example:
<div if={ isPremium }>
<p>This is for premium users only</p>
</div>
Again, the expression can be just a simple property or a full javascript expression. The if
directive is a special attribute:
true or (truthy)
: mount a nested component or add an element to the templatefalse or (falsy)
: unmount an element or a component
Fragments conditional
>=4.2.0
The if
directives can be used also without the use of a wrapper tag. Thanks to the <template>
tag you can render only the content of an if condition:
<template if={isReady}>
<header></header>
<main></main>
<footer></footer>
</template>
The <template>
tag will be just used to wrap a html fragment that depends on a Riot.js directive, this feature is available also for loops