maomi
Introduction
Guide
Documents

Template Branches

If statements

The if statements are allowed.

#[component(Backend = DomBackend)]
struct MyWebsite {
template: template! {
if self.my_boolean_data {
<div> "My Optional Element" </div>
} else {
<div> "Another Element" </div>
}
},
my_boolean_data: bool,
}

Likewise, the if-let statements are also allowed.

#[component(Backend = DomBackend)]
struct MyWebsite {
template: template! {
if let Some(s) = &self.my_option {
<div> { s } </div>
}
},
my_option: Option<String>,
}

Match statements

The match statements are just like common rust code.

#[component(Backend = DomBackend)]
struct MyWebsite {
template: template! {
match &self.my_option {
Some(s) => {
<div> { s } </div>
}
None => {
<div> "Another Element" </div>
}
}
},
my_option: Option<String>,
}