Skip to content
Marcus edited this page Oct 14, 2015 · 2 revisions

The let directive can be used to bind names to values.


Syntax

$$#let varA = exprA; varB = exprB; ... $$
   ...
$$/let$$
  • May be empty: no
  • May be nested: yes

The expressions are evaluated within the current scope. Note that the let directive does not introduce a new scope itself. This means it is not possible to access a variable in the current scope that has been bound to a new value using a let expression. There is, however, a way to work around this by using a $$#block$$ expression.

$$#block$$
   $$#let varA = $1.Foobar$$
      ...
   $$/let$$
$$/block$$

Note the use of the $1 namespace to access the parent scope here ($0 is the current scope).

The let directive has another syntax form which can be used to reuse "snippets" of a source file. It binds a variable to the output of the templater like so:

$$#let common_stuff$$
  $$foobar$$ is repeated
$$#out$$
   $$#if some_condition$$
      Some condition is true, output $$common_stuff$$.
   $$#else$$
      Else output $$common_stuff$$.
   $$/if$$
$$/let$$

Thus the let keyword is followed by a variable name and then the part of the body until $$#out$$ is considered the definition of type String. The actual output of this directive is the body part from $$#out$$ until $$/let$$.

Note that the #define and #undef directives won't function within a let directive if they match the name that has been bound.

Notes

#let is probably only of limited use as #define coupled with #block provide the same functionality.

Clone this wiki locally