Whilst the syntax for modules makes use of HTML-style comments,
there is nothing preventing the use of templates for non-HTML
purposes.
Chunks are delimited by <!-- BEGIN name --> some text <!--
END --> where name specifies the name of the chunk, and
some text is replaced by whatever you wish to appear within
the chunk. Chunks can be nested but this is only for
convenience: a nested chunk is never output as part of its
parent chunk. The purpose of allowing nesting is so that the
template can be constructed so that it itself renders acceptably
in a browser.
Variables can be specified in the content of the chunk by
##name## where name is the variable name. In order to
prevent the variables from appearing in the template when
rendered in a browser, the variable may be set in a comment as
long as it's the only thing in the comment, e.g. <!--
##name## -->
Typical use is to use the splice syntax (ghc needs -fth for
this) to include the chunk definitions in the currrent module,
e.g.
$(chunksFromFile "/path/to/templates/template_01.html")
This causes, at compile time, the template to be parsed and for
the chunks to be converted into data declarations which are
instances of both Show (for debugging purposes) and Chunk
(for formatting purposes). The template is thus incorporated
directly within the executable eliminating the dependency on the
template at runtime. This also means that if you just change the
template then you must recompile with -fforce-recomp inorder to
force the recompilation.
The naming convention used converts the names of chunks to
Chunk_name and chunk variables to fields in the data type
with names of chunk-name_var-name. The function
showChunksData exists to allow you to inspect these.
|