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: - out_dir - Output directory for BEAM files (by default no BEAM files are created)
- vars - Variables (and their values) to evaluate at compile-time rather than render-time (defaults to []).
- force_recompile - Recompile the module even if the source's checksum has not changed. Useful for debugging.
- compiler_options - Proplist passed directly to compiler:forms/2 (defaults to [verbose, report_errors]
- doc_root - Included template paths will be relative to this directory; defaults to the compiled template's directory.
- custom_tags_dir - Directory of DTL files (no extension) includable as tags. E.g. if $custom_tags_dir/foo contains <b>{% bar %}</b>, then {% foo bar=100 %}" will evaluate to 100`. Get it?
- reader - {module, function} tuple that takes a path to a template and returns a binary with the file contents. Defaults to {file, read_file}. Useful for reading templates from a network resource.
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
|