Skip to content

Syntax Reference

Jacob Jensen edited this page Oct 13, 2017 · 2 revisions

Here is a complete list of the current syntax as of 0.2.32

Code Block

@{
    // Any piece of D code will fit here
    // You can declare functions, classes, variables etc.
}

Example

@{
    auto getFoo() {
        return "bar";
    }
}

Escaping Text

@(Text or symbols to escape, this can even be D code or Diamond expressions)

Example

@(<span>The tags are escaped</span>)

Escaping Variables/Expressions (0.3.0+)

@$=variable_to_escape;
@$=(expression_to_escape);

0.2.32 Fallback

@=escape(variable_to_escape);
@=escape(expression_to_escape);

Example (0.3.0)

@:auto foo = "<span>Bar</span>";
@$=foo;

Example (0.2.32)

@:auto foo = "<span>Bar</span>";
@=escape(foo);

Unescaped Variable/Expression

@=variable_to_not_escape;
@=(expression_to_not_escape);

Example

@:auto foo = "<span>Bar</span>";
@=foo;

Linear expressions

@:linear_code

@:linear_code {
    Html or Diamond expressions here
}

// Linear code will work with nested {}, [] or ()

Example

@:foreach (person; persons) {
    <span>Person: @=person.name;</span>
}

Comments

@* Comment here *

@*
    Comment here
*

// Alternative using linear expressions
@:// Comment here

Example

@*
   Hello World!
*

Metadata Block

@[
    // Metadata here
]

Example

@[
    layout:
        layout
]

Placeholders

@<placeholder_here>

Example

@<title>