https://github.com/thheller/zview
zview - Erlang Template Engine (inspired by erlydtl, Django Templates, Liquid and others.)
https://github.com/thheller/zview
Last synced: about 1 year ago
JSON representation
zview - Erlang Template Engine (inspired by erlydtl, Django Templates, Liquid and others.)
- Host: GitHub
- URL: https://github.com/thheller/zview
- Owner: thheller
- Created: 2011-09-28T14:03:41.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2012-01-18T23:22:44.000Z (over 14 years ago)
- Last Synced: 2025-02-10T11:13:59.712Z (over 1 year ago)
- Language: Erlang
- Homepage: http://github.com/thheller/zview
- Size: 167 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
zview - Introduction
==============
This is zview, a Template Engine for Erlang (at least it will be sometime in the future).
Its in early alpha and not recommended for use (half of the Stuff doesnt work yet).
It started out as a fork of erlydtl since I wanted to address some of the issue I had
with it. Turned out that changing those was way more work than expected and would have
broken most DTL Templates anyway, so I started from scratch, only reusing the
erlydtl\_scanner and erlydtl\_parser, although those were modified too.
I'll highlight the major differences later, first lets have a look:
{{ title | default: 'Default Page Title' }}
The usual for loop
- {{ x }}
{% for x in items %}
{% endfor %}
The usual if/else
{% if foo == 'bar' %}
bar
{% else %}
{{ foo }}
{% endif %}
Simple Tags
{% render "other_template" %}
Simple Block Tag, vars declared in Args are only available inside the do/end Block
{% with var1="test" var2=some.nested.json.data.struct do %}
{{ var2 }}
{% end %}
Not defined, outputs nothing (instead of undefined like erlydtl)
{{ var1 }}
Custom Tags are defined by prefixing it with alias@
{% ext@simple_tag arg1=title %}
Custom Tags can have Blocks too
{% ext@custom_tag also="has args" do %}
inside custom tag
{% end %}
Should look familiar to anyone having used erlydtl, Django Templates or Liquid before.
Documentation
-----
TODO!!!
Differences in the Templates itself
---
Main Difference is that I wanted to be able to have the
Template export Key/Value Pairs to the caller.
{% export meta="data" some=var %}
{% export block do %}
Super Duper Title
{% end %}
{ok, Content, Exports} = zview:render("my_template.tpl", [{var, "test"}]).
Exports will be a proplist containing [{meta, "data"}, {some, "test"}, {block, "h1..."}].
I wanted this as a stricter alternative to View Inheritance. Templates are completely standalone
and cannot have dependencies to the outside (other than the runtime, tags). You could still
achieve the same as View Inheritance with a simple loop and some exports.
{% export layout="my_page_layout.html" %}
{% export content do %}
Page Content
{% end %}
Custom Block Tags:
{% ext@some_tag kw="args" var=some.list do %}
tag content
{% end %}
Custom Tags:
{% ext@some_tag with="args" %}
Filters may have multiple Args, and of course can be custom too:
{{ some_var | mod@some_filter: 'arg1', arg2, 'arg3' }}
Differences in the Runtime
---
Way too many to even start comparing them.
"Context" Variables
----
There are Variables that are only availble inside certains contexts/blocks. They are prefixed by "$".
$loop
---
Same as forloop in DTL, Liquid and only available inside for loops, will raise an Error
if called outside for loop.
{{ $loop.index }} Also has the common forloop attributes (index, index0, rindex, rindex0, first, last, length)
$vars
---
{Key, Value} Pairs of all Vars given to the Template render fun. Mainly intended for debugging.
{% for key, value in $vars %}
Key: {{ key }} Value: {{ value }}
{% endfor %}
Probably more I cant think of right now.
Thanks
===
- [erlydtl](https://github.com/evanmiller/erlydtl)
Without it I probably wouldnt even have started, never written a parser/compiler before so
it was a very valuable Reference. Also obviously Django Templates and Liquid for Inspiration.
- [kvc](https://github.com/etrepum/kvc)
Used to do most Variable Lookups. Its awesome.
License
---
MIT