> _Alright, fine. I can't stack ten plates, but I'll stack templated text files
> like it's nobody's business._
> - **Me**
## Tags
### Assert
Verifies that a [condition](#conditions) is truthy before continuing, will throw
at compile-time otherwise.
```tenplate
{% assert "1" /%}
```
### Call
Processes an external file inline, modifying the existing [context](#g-context)
along the way.
```tenplate
{# ./functions/header.tenplate #}\
{% fn header(lvl, txt) %}\
{{ txt }}\
{% /fn %}\
```
```tenplate
{% call "./functions/header.tenplate" /%}\
{% exec header("2", "Hello") /%}
```
```txt
Hello
```
The following other tag(s) were used in this example.
- [_exec_](#t-exec)
- [_fn_](#t-fn)
###
Instructs the compiler to skip all content contained within the open/close tags.
```tenplate
{# this is a comment #}
```
### Compile
Processes an external file inline without modifying the existing
[context](#g-context).
```tenplate
{# ./set/name.tenplate #}\
{% set name %}Frankie{% /set %}\
```
```tenplate
{% set name %}Matthew{% /set %}\
{% compile "./set/name.tenplate" /%}{{ name }}
```
```txt
Matthew
```
The following other tag(s) were used in this example.
- [_set_](#t-set)
### Exec
Executes a function already read into the current [context](#g-context).
Arguments can be excluded from right-to-left.
```tenplate
{% fn commas(a, b, c) %}\
{{ a }}, {{ b }}{% if c %}, {{ c }}{% /if %}\
{% /fn %}\
{% set d %}foo{% /set %}\
{% set e %}bar{% /set %}\
{% exec commas(d, e, "baz") /%}
{% exec commas(d, e) /%}
```
```txt
foo, bar, baz
foo, bar
```
The following other tag(s) were used in this example.
- [_fn_](#t-fn)
- [_set_](#t-set)
### Extend
Sets a single file as an outer template to process with the result of the
current file. The [context](#g-context) will be passed along and the
[content](#g-content) will be assigned to the special [context](#g-context)
[variable](#g-variable) `CONTENT`. If the extend tag is used multiple times
within the same template, the last tag used wins.
```tenplate
{# ../papa.tenplate #}\
{% assert name /%}\
{% assert paragraph /%}\
{{ name }}
{{ paragraph }}
\
{% if CONTENT %}
{{ CONTENT }}
\
{% /if %}
```
```tenplate
{% extend "../papa.tenplate" /%}\
{% set name %}Frankie{% /set %}\
{% set paragraph %}This is a paragraph.{% /set %}\
And here is some output content.
```
```txt
Frankie
This is a paragraph.
And here is some output content.
```
The following other tag(s) were used in this example.
- [_assert_](#t-assert)
- [_if_](#t-if)
- [_set_](#t-set)
### Fn
Registers a [function](#g-function) in [context](#g-context) which can be called
using the [exec](#t-exec) tag. A function can have anywhere from 0 to _n_
arguments.
```tenplate
{% fn commas(one, two, three) %}\
{{ one }}, {{ two }}{% if three %}, {{ three }}{% /if %}.\
{% /fn %}\
{% exec commas("First", "Second", "Third") /%}
{% exec commas("First", "Second") /%}
```
```txt
First, Second, Third.
First, Second.
```
The following other tag(s) were used in this example.
- [_exec_](#t-exec)
- [_if_](#t-if)
### Fordir / Else
Loops through each directory within a given directory. The element
[variable](#g-variable) will contain the path of the directory. If a name is
given for the loop [variable](#g-variable) (`as dir_loop` in the example below),
the [loop context](#loop-context) will be stored with the given variable as a
prefix. The `else` condition is triggered when no elements are found for the
loop.
Assume the following file stucture for the next example.
```txt
./
\
a-dir/
\
First/
Second/
Third/
```
```tenplate
{% fordir d in "./a-dir" as dir_loop %}\
{% if dir_loop.isfirst %}{% else %}, {% /if %}\
"{{ d }}"\
{% else %}\
{# no directories in "./a-dir" #}\
{% /fordir %}
```
```txt
"./a-dir/First", "./a-dir/Second", "./a-dir/Third"
```
The following other tag(s) were used in this example.
- [_if_](#t-if)
### Foreach / Else
Loops through each value in a given variable in [context](#g-context). See
[set](#t-set) for info on how a [variable](#g-variable) can have multiple
values. The optional [loop context](#loop-context) definition behaves
identically to the [fordir](#t-fordir) tag.
```tenplate
The siblings are \
{% set names %}Matthew{% /set %}\
{% set names %}Frankie{% /set %}\
{% set names %}Karina{% /set %}\
{% foreach name in items as name_loop %}\
{% if name_loop.isfirst %}{% else %}, {% /if %}\
{% if name_loop.islast %}and {% /if %}\
{{ name }}\
{% /if %}\
{% if name_loop.islast %}.{% /if %}\
{% else %}\
{# no items #}
{% /foreach %}
```
```txt
The siblings are Matthew, Frankie, and Karina.
```
The following other tag(s) were used in this example.
- [_if_](#t-if)
### Forfile / Else
Loops through each file in a given directory. The element
[variable](#g-variable) will contain the path. The optional
[loop context](#loop-context) definition behaves identically to the
[fordir](#t-fordir) tag.
Assume the following file stucture and contents for the next example.
```txt
./
\
sibling.tenplate
siblings/
\
first.tenplate
second.tenplate
third.tenplate
```
```tenplate
{# ./sibling.tenplate #}\
{% assert sibling.filepath /%}\
{% call sibling.filepath /%}\
{% assert sibling.name /%}\
{% assert sibling.description /%}\
{{ sibling.name }} | {{ sibling.description }}. |
\
```
```tenplate
{# ./siblings/first.tenplate #}\
{% set sibling.name %}Matthew{% /set %}\
{% set sibling.description %}The elder{% /set %}\
```
```tenplate
{# ./siblings/second.tenplate #}\
{% set sibling.name %}Frankie{% /set %}\
{% set sibling.description %}The poor middle-child{% /set %}
```
```tenplate
{# ./siblings/third.tenplate #}\
{% set sibling.name %}Karina{% /set %}\
{% set sibling.description %}Da baby{% /set %}\
```
```tenplate
Name |
Description |
\
{% set sibsdir %}{% path "./siblings" /%}{% /set %}\
{% set sibtemplate %}{% path "./sibling.tenplate" /%}{% /set %}\
{% forfile sibling.filepath in sibsdir %}
{% compile sibtemplate /%}\
{% else %}\
{# no files in "./a-dir" #}\
{% /fordir %}
```
```txt
Name |
Description |
Matthew | The elder. |
Frankie | The poor middle-child. |
Karina | Da baby. |
```
The following other tag(s) were used in this example.
- [_call_](#t-call)
- [_compile_](#t-compile)
- [_path_](#t-path)
- [_set_](#t-set)
### Get
Gets a value from a [variable](#g-variable) in [context](#g-context).
```tenplate
{% set msg %}Hi{% /set %}\
{{ msg }}
```
```txt
Hi
```
The following other tag(s) were used in this example.
- [_set_](#t-set)
### If / Else
Compiles one of two code-paths depending on whether the [condition](#conditions)
evaluates to true or false. The `else` tag is an optional inclusion.
```tenplate
{% if "1" %}\
True\
{% else %}\
False\
{% /if %}
```
```txt
True
```
### Include
Includes a file inline with compilation. Useful for including files which
contain `Ten Plates` syntax.
```tenplate
{# ./includes/file.tenplate #}\
{% set name %}Frankie{% /set %}\
```
```tenplate
{% include "./includes/file.tenplate" /%}
```
```txt
{# ./includes/file.tenplate#}\
{% set name %}Frankie{% /set %}\
```
### Set
Sets a value for a [variable](#g-variable) in [context](#g-context). When
multiple values are set for a given [variable](#g-variable), the previous value
is not overwritten, but is masked by the new value. These values can then be
iterated over in the order in which they were set using the
[for-each](#t-foreach) tag.
```tenplate
{% set v %}1{% /set %}
```
## Conditions
A set of one or more of logical assertions evaluating to true or false. These
can be nested using parenthetical notation or conjoined using the
short-circuiting _and_ or _or_ operators. The values contained within conditions
are evaluated in their _string_ form so `Ten Plates` performs boolean casting
on all values.
```tenplate
{# true #}{% assert "1" /%}
{# true #}{% assert "Hello, World!" /%}
{# false #}{% assert "0" /%}
{# false #}{% assert "" /%}
{# false #}{% assert a /%}
{# true #}{% set a %}1{% /set %}
{# true #}{% assert "1" == a /%}
{# true #}{% set b %}0{% /set %}
{# true #}{% assert a || b /%}
{# true #}{% assert (a && b) || "1" /%}
{# true #}{% set d %}500{% /set %}
{# true #}{% assert d > a /%}
{# true #}{% assert "501" > d /%}
{# true #}{% assert "501" >= d /%}
{# true #}{% assert "501" != d /%}
{# true #}{% assert "501" <= d /%}
{# true #}{% assert "501" < d /%}
```
## Glossary
**Content**: The final output of a tenplate.
**Context**: Functions, values, and other data currently
in-scope and usable.
**Function**: A block of tenplate keyed with a given
name for future retrieval and compilation against an optional set of named
arguments.
**Variable**: A value in context keyed with a given
name for future retrieval.