Home › Templates
Rendering .lasso, .lasso9, and .lp files with bracket tags and LDML page-control tags.
.lasso file — text passes through and bracket expressions are evaluated.
LaiRu renders files with the extensions .lasso, .lasso9,
and .lp. Any other file is served as a static asset.
When a request targets a directory, LaiRu tries
index.lasso, index.lasso9, index.lp,
then index.html in order.
Code between [ and ] is evaluated as a Lasso expression.
The result is inserted into the output unless it is void or null.
Assignments and declarations produce no output.
Hello [local(name) = 'Ada'][#name]! <!-- renders: Hello Ada! --> <p>2 + 3 = [2 + 3]</p> <!-- renders: <p>2 + 3 = 5</p> -->
LaiRu also recognises the <?lasso … ?> and
<?= … ?> delimiters:
<?lasso
local(count) = 0
loop(3) => { count = count + 1 }
?>
<p><?= #count ?> iterations.</p>
<!-- renders: <p>3 iterations.</p> -->
LaiRu supports the legacy LDML bracket tags used in historic Lasso pages. These sit alongside the modern bracket-expression form.
[if(#hour < 12)] Good morning! [else(#hour < 17)] Good afternoon! [else] Good evening! [/if]
[loop(5)] Row [loop_count] [/loop]
The [no_square_brackets] tag disables bracket interpretation for the
remainder of the template, allowing literal square brackets in the output:
[no_square_brackets] [this text is now literal and not evaluated]
Use [include('path')] to embed another template file.
The path is resolved relative to the including file’s location,
not the document root. Includes are sandboxed to the template root and recursive
include chains are rejected.
<!-- from /pages/article.lasso -->
[include('../includes/header.lasso')]
<main> ... </main>
[include('../includes/footer.lasso')]
Template includes share the same variable space as the including file.
Use thread variables ($name) to pass values into includes:
<!-- mypage.lasso -->
[$page_title = 'My Page']
[include('../includes/header.lasso')]
<main>...</main>
[include('../includes/footer.lasso')]
<!-- includes/header.lasso -->
<title>[$page_title]</title>
Templates can set HTTP response properties before any output is written:
[response_status(201)]
[response_header('X-Powered-By', 'LaiRu')]
[response_content_type('application/json')]
[response_cookie('theme', 'dark', -httpOnly, -path='/')]
[response_no_cache]
The LaiRu service caches template source by path, length, and mtime. Parsed Lasso code
fragments are cached by source text. Diagnostics from cached fragments are remapped to
the active template source coordinates after reuse. Disable caching with
LAIRU_TEMPLATE_CACHE=0 and LAIRU_PARSE_CACHE=0.