Noel Variables
Noel templates can define and reference simple string variables which can
also be resolved as boolean values. Variables are useful for storing constants
(e.g. color values), abbreviations, and any values that may change.
Variable names must begin with a letter and can contain letters, digits,
dashes (-), and underscores (_). Variable names are case sensitive. Variables
are defined using the built-in <DEF> tag whose parameters
become variable definitions. The HTML spec is followed for double- or
single-quoting and escaping quotes and backslashes.
Here is an example from a website I am currently working on:
<def SiteName="Photomaki">
<def FreeStorageLimit=50 PremiumStorageLimit=100 PremiumCost='$24.95'>
<def PopupTarget="_photomaki_popup">
Basic Variable Resolution
Variables are inserted into output using
the following notation:
$ [ ! ] [ * ][ { ][ a..z, A..Z ][ a..z, A..Z, 0..9, -, _ ][ } ]
Normal notation: $mud-Slinger_9
Silent notation: $!mud-Slinger_9
Required notation: $*mud-Slinger_9
Formal notation: ${mud-Slinger_9}
|
When Noel encounters a string such as "$foo" and a variable 'foo' is defined,
it replaces $foo with the value of 'foo'. If 'foo' is not defined, $foo is
output. To hide a variable reference when the variable is undefined use the
silent notation $!foo, so that "$foo" becomes "". To prevent confusion
with surrounding characters (e.g. "$fool"), use formal notation (e.g. "${foo}l".)
$foo
$!foo
<def foo=42> $foo
<def foo=42> $Foo
<def foo=42> $fool
<def foo=42> ${foo}l
| => |
$foo
42
$Foo
$fool
42l
|
See the Variable Resolution
page for more details about the various ways that variables can be
displayed.
Boolean Values
Variables can be resolved as boolean values when used in the <IF>
tag conditional.
If a variable is undefined or equal to the string "false", it resolves as
boolean false. Otherwise it resolves as boolean true.
When a variable
is defined without a value, it is initialized as "true". When a variable
is defined with the ! symbol (logical inversion), it is initialized as
"false".
<def foo> $foo
<def !foo> $foo
<if foo>yes<else>no<end>
<def foo> <if foo>yes<else>no<end>
<def !foo> <if foo>yes<else>no<end>
<if false>yes<else>no<end>
| => |
true
false
no
yes
no
no
|
Special Variables
$SOURCE is set to the filename of the final 'leaf' source file that
is used to construct a page.
$DESTINATION is set to the filename of the
matching destination file.
Undefining Variables
Variables can also be undefined via the built-in <UNDEF> tag. Example:
|
<undef SiteName PopupTarget>
|
Variable Escaping
Sometimes you want $foo to be $foo, not the value of 'foo'. This is especially
true if you are passing along variable references to be handled by a template
engine that also uses '$' variable references. On Worldisround I have Noel
content that is passed through Noel then undergoes two passes through
Velocity. To escape the '$' symbol, add a backslash for each time that it
needs to be escaped. (Fortunately, this does not mimic the way
the Velocity Template Language handles escaping, which I found confusing.)
$foo
\$foo
\\$foo
\\\$foo
$!foo
\$!foo
\\$!foo
\\\$!foo
<def foo=42> $foo
<def foo=42> \$foo
<def foo=42> \\$foo
<def foo=42> \\\$foo
| => |
$foo
$foo
\$foo
\\$foo
$foo
\$foo
\\$foo
42
$foo
\$foo
\\$foo
|
See also the Copy Content delimiter for cleaner,
broader content escaping.