|
|
An ErlyDTL template is a text file (e.g.: a HTML or CSS file) containing variables to control the runtime template content, tags to control the runtime template logic and comments, which get filtered out.
ErlyDTL compiles template source files to Erlang bytecode.
Basic examples illustrating the syntax:
| source code: | at runtime: | |
| Variables (e.g.: a=7) | text {{ a }} text | text 7 text |
| Tags (e.g.: for-tag with variable b=[1,2,3]) | {% for i in b %} <{{ i }}> {% endfor %} | <1> <2> <3> |
| Comments | text {# hello #} text | text text |
Features:
- Template inheritance
- Variables can optionally be pre-set at template compilation, this is useful for stuff which doesn't change often.
- Performance: templates get pre-rendered as much as possible at compilation time
- Built-in tags:
- autoescape
- block
- cycle (only in loop context)
- extends
- for
- loops over a list or tuple
- also resolves nested, dot-separated variable attributes
- if
- ifequal
- ifnotequal
- include
- now
- Built-in filters:
- add
- capfirst
- center
- first
- fix_ampersands
- force_escape
- escapejs
- date
- join
- last
- length
- length_is
- linebreaksbr
- ljust
- lower
- rjust
- upper
- urlencode
- Custom tags:
- tag - a generic tag for assigning a template to a user defined custom tag (template filename becomes custom tag name). A template compiling option allows the user to define a custom directory for extending or overwriting the built-in custom template-based tags, which currently are:
- flashvideo (for HTML embedding flash video)
- call (inserts the rendered output of an already compiled template beamfile)
- Templates accept variables as property list, dict, gb_tree or parameterized modules and the actual values can be numbers or strings (lists or binaries)
- Variables, Tags and Comments can be wrapped with HTML comments (<!--, -->) for a possibly better integration with certain HTML editors / browser previews
- When rendering fails (e.g: when variables are not set) the template rendering function returns an error report in the form of {error, Reason}
- Optional recompilation-skip if compiled template exists already and template source checksum has not changed
- Template source reader default function (file:read_file/1) can be overwritten with custom function, e.g. for reading templates from network storage such as Amazon S3.
Requirements:
- Erlang R12B
ToDo:
- implement all tags and filters defined in original Django
- allow funs as compile / render options for:
- variables
- output writer callback
- source reading function
