Nova · Layouts
Conditional in a loop
A condition inside a for reads the element of that turn, so each row decides for itself.
{
id: 'conditional-in-loop',
data: {
seats: [
{ id: 'C4', taken: true },
{ id: 'C5', taken: false },
{ id: 'C6', taken: true },
],
},
layout: {
component: 'Stack',
children: [
{
for: '$.seats',
as: 'seat',
key: 'id',
do: {
if: '$seat.taken',
then: { component: 'Text', children: '{{$seat.id}} is taken' },
else: { component: 'Text', children: '{{$seat.id}} is free' },
},
},
],
},
}C4 is taken
C5 is free
C6 is taken
Nothing. It is only drawn.
{
seats: [
{ id: 'C4', taken: true },
{ id: 'C5', taken: false },
{ id: 'C6', taken: true },
],
}C4 is taken C5 is free C6 is taken
Left: the action as the package ships it. Right: the same action running in this page, rendered with this site’s components. Below: the action run as the example specifies, on the installed package.