@if
Keeps its body when its condition holds, and its detail, if it has one, when it fails.
On this page
#Attributes
whenThe condition, an expression without braces:
audience = teacher, n >= 3 and {{show-value}}, not answers. It takes <, <=, >, >=, = and !=, which compare loosely (Blue = blue, 1.0 = 1), == and !==, which compare exactly, and, or, not, x in 0..5 (a < beside the dots leaves that end out: x in 0..<5, x in 0<..), and true and false.#Allowed content
Body { }The content to keep when the condition holds — any Chalk that is legal where the @if is written
#Examples
@let(audience: teacher)
@if(when: audience = teacher){
note{
Answers are collected in the closing scene.
}
}[
note{
Answer each question before moving on.
}
]@let(answers)
@if(answers){
The answers follow each question.
}#Notes
- Beside
=a word nothing declares is a name, kept as written and possibly several words:audience = teacher,country = new zealand; quoted,"new zealand", it is text and nothing else. Two texts compare as text, so"1.0" = "1"fails. - A bare key tests for
trueand!keyforfalse:(answers)iswhen: answers,(!answers)iswhen: not answers, and several AND together. - Inside a condition a hyphen is a minus, so a hyphenated constant is written in braces:
(when: {{show-value}} and n > 2). - A condition is required: @if: requires a condition —
(when: …), or a barekey/!key. - A
key: valuepair is refused with the fix: @if:audience: teacheris not an attribute of— write(when: audience = teacher). - A condition gives a boolean, so a number is refused: @if:
k + 1gives a number where a boolean is wanted — compare it, as ink + 1 > 0. - The constant is declared above the
. A name nothing declares is the word itself:(when: k > 3)is @if:kis not a valid number. A template's attributes and abinding, including a row's cells, count as constants. - A condition is decided as the document compiles, so one that reads a live value is refused:
is decided while the document compiles and cannot depend on#f.slope.