/

On this page

Conditional statements

The .if function creates a conditional statement:

  1. The first parameter is the condition (Boolean to evaluate.
  2. The second parameter is a parameter-less lambda that runs only if the condition is true.

Example 1

.if {yes}
    Hello, Quarkdown!

Hello, Quarkdown!

Nesting

The function returns the lambda’s result if the condition is satisfied, or nothing otherwise. This means the function propagates its content up the call stack.

Example 2

<!-- Read this from bottom to top -->

.if {yes}
    .if {no}
        .if {yes}
            .if {yes}
                Hello!

This behavior lets you use the function as part of any expression. For example, you can use it to conditionally include content inside layout functions, such as stacks.

Example 3

.row gap:{1cm}
    A

    .if {.iseven {3}}
        B

    C

A

C

Negation

The .ifnot function is a shorthand that inverts .if’s behavior, returning a value only if the condition is not satisfied.

Quarkdown does not yet have an else statement, but you can emulate one using the .let function:

Example 4

.let {.iseven {3}}
    condition:
    .if {.condition}
        3 is even!
    .ifnot {.condition}
        3 is odd!

3 is odd!

.ifnot {.condition} is equivalent to .if {.condition::not}