An initial cut at describing the logic control capabilities of
the HTDB scripting language.
The HTDB scripting language is purposefully quite simple, but extensible.
The following constructs make up the entirety of the language:
-
define
-
include
-
if/elseif/else/endif
-
while
-
loop
define
htdb resource documents are composed of one of more blocks of
script called resources. such blocks are initiated when
#define is found, and terminate at the occurence
of another define, or the end of the file.
comment lines are those which have the # character in the leftmost
column. comments may be interspersed within a resource block.
example:
#define pageTitle this is a test page
#define pageColor #cfcfcf
#
# this is a comment
#
#define index.html
<html>
<head><title>${pageTitle}</title></head>
<body bgcolor=${pageColor}>
hello world
|
include
a great strength of the HTDB system is the flexibility of the designer to
templatize layouts and/or include elements across many documents. the #include
directive is used to "suck-in" resource common definitions to make them available
to a document.
example:
#include macros
#define index.html
${somethingDefinedInTheMacrosResourceFile}
|
if/elseif/else/endif
example using the environment variable _current_month:
#live if (getval(_current_month) == Jan)
the month is January
#live else if (getval(_current_month) == Feb)
the month is February
#live else
the month is ${_current_month}
#live endif
|
yields:
example using the function function random():
#live if (random(10) > 8)
BIG
#live else if (random(10) > 4)
MEDIUM
#live else
SMALL
#live endif
|
yields:
loop
example:
#live loop(i, 1, 10)
${i}<br>
#live endloop
|
yields:
example using loop and functions:
#live loop(i, 6, 12)
${num2month(${i})}<br>
#live endloop
|
yields:
June
July
August
September
October
November
December
|
example using loop and functions as loop limits:
#live loop(i, 1, ${random(12)})
${num2month(${i})}<br>
#live endloop
|
yields:
January
February
March
April
|
while
${define(randImage_1,88)}
${define(randImage_2,128)}
${define(randImage_3,195)}
${define(randImage_4,182)}
${define(randImage_5,39)}
#live while (t = randImage_*)
randImage_${t}:
<img src="/images/random/_${randImage_${t}}.jpg"
width="75" height="75">
#live endwhile
|
yields:
alternate implementation using looping and random:
${define(loopStart, 1)}
${define(loopEnd, 5)}
#live loop (i, ${loopStart}, ${loopEnd})
randImage_${i}:
<img src="/images/random/_${random(200)}.jpg"
width="75" height="75">
#live endloop
|
yields:
|