|
From: | Ivan Raikov |
Subject: | Re: [Chicken-users] Ersatz question |
Date: | Wed, 6 Mar 2013 15:41:00 +0900 |
-IvanThis will create an ersatz template variable called "posts" which contains a list of Tobj values. Tobj is the wrapper for objects with named fields in Ersatz.Hi Matt,Thanks for trying again to use Ersatz. The models argument is an alist where the key is a symbol (the name of the variable),
and the value is of type tvalue, which is a datatype defined in ersatz-lib.scm. So your example could work as follows:
(let* ( (source
#<<EOFEOF
{% for p in posts %}
<div class="blog-post">
<h3>{{ p.title }}</h3>
<div class="post-body">
{{ p.body }}
</div>
</div>
{% endfor %}
))
(from-string source models:
`((posts .
,(Tlist
(list (Tobj `((title . ,(Tstr "Post One title"))
(body . ,(Tstr "Post One body"))
))
(Tobj `((title . ,(Tstr "Post Two title"))
(body . ,(Tstr "Post Two body"))
))
))
)
))
It is basically equivalent to an alist, except that the values must be Ersatz values (i.e. tvalue datatype).
The above code can be greatly simplified of course, so if you have some typical patterns of template use, just let me know, and I will implement them.
Thanks,On Wed, Mar 6, 2013 at 3:07 PM, Matt Gushee <address@hidden> wrote:
_______________________________________________Hi, folks--I am trying again to learn how to use Ersatz. I am trying to render pages that display sequences of similar components (e.g. blog posts). The template syntax includes 'for' loops, e.g.
{% for p in posts %}<div class="blog-post"><h3>{{ p.title }}</h3><div class="post-body">{{ p.body }}
</div></div>{% endfor %}Or ... I'm pretty sure the following would work in Jinja2 (where the 'posts' variable is a list in the form [[<post>, <body>] ...]):
{% for title, body in posts %}<div class="blog-post"><h3>{{ title }}</h3><div class="post-body">{{ body }}</div></div>{% endfor %}So, do these constructs work in ersatz? If so, what data structures do I want to pass as the models: argument when rendering the templates?
Thanks for any info!
--Matt Gushee
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users
[Prev in Thread] | Current Thread | [Next in Thread] |