If Statements

Use if to render one component tree when a Rust condition is true. The condition must be wrapped in parentheses. Add else if and else branches when needed.

if (user.is_admin) {
    Text {
        text: "Administrator"
        color: emerald-700
    }
} else if (user.is_member) {
    Text { text: "Member" }
} else {
    Link {
        text: "Sign in"
        href: "/sign-in"
    }
}

Conditions are Rust expressions evaluated in the scope where render_qtml! is called. Use $name only when inserting a binding into a property value; do not prefix names in the condition itself.

if (items.is_empty()) {
    Text { text: "No items yet." }
}