My favorites | Sign in
Project Logo
                
Search
for
Updated Feb 28, 2009 by emmiller
Labels: Featured
Overview  
Introduction and notes on creating, compiling and using ErlyDTL templates

Template compilation:

erlydtl exports compile/2 and compile/3:

erlydtl:compile(Input, Module::atom()) ->
    ok | {error, Reason::terms())}

erlydtl:compile(Input, Module::atom(), Options::PropertiesList) -> 
    ok | {error, Reason::term()}

When Input is a string, it is interpreted as a filename. When Input is a binary, it is interpreted as the template code; in this case, note that the generated bytecode is then loaded directly into memory, and no beam file gets generated.

Options include:

Usage (of a compiled template):

my_compiled_template:render(Variables) -> {ok, Result::iolist()} | {error, Err::string()}

Variables is a proplist, dict, gb_tree, or a parameterized module (whose method names correspond to variable names). The variable values can be atoms, strings, binaries, or (nested) variables.

my_compiled_template:source() -> {Filename::string(), CheckSum::string()}

Name and checksum of the original template file.

my_compiled_template:dependencies() -> [{Filename::string(), CheckSum::string()}]

List of names/checksums of templates included by the original template file. Useful for frameworks that recompile a template only when the template's dependencies change.

Examples:

Run from Erlang interactive shell:

erlydtl_functional_tests:run_tests().

this compiles the example templates, puts the generated beamfiles into the ebin folder and the rendered output into examples/rendered_output folder.

Tests:

Run from Unix shell:

make test


Sign in to add a comment
Hosted by Google Code