with first contruct doesn't compile

22 views
Skip to first unread message

Ward (TTY)

unread,
Apr 11, 2012, 2:56:03 PM4/11/12
to erlydt...@googlegroups.com
The following template:

{% with restaurant.restaurant_images|first as img %}
<img src="/restaurant_image/{{ img.filekey }}/200x200" title="{{ img.caption }}" />
{% endwith %}

failes with:

ERROR: Compiling template templates/test.dtl failed:
  {error,{"templates/test.dtl",
          [{{1,19},erlydtl_parser,["syntax error before: ","'.'"]}]}}

This seems to be valid in django templates though: example

How to make this work?

Evan Miller

unread,
Apr 11, 2012, 4:06:51 PM4/11/12
to erlydt...@googlegroups.com
IIRC the required syntax is

{% with img=restaurant.restaurant_images|first %}
...
{% endwith %}

--
Evan Miller
http://www.evanmiller.org/

Ward (TTY)

unread,
Apr 12, 2012, 2:49:34 AM4/12/12
to erlydt...@googlegroups.com
Hi Evan,

Thx, that compiles. I think I made another mistake, as it doesn't work yet:

test.dtl:

{% with img=restaurant.restaurant_images|first %}
{{img}}
<img src="/restaurant_image/{{ img.filekey }}/200x200" title="{{ img.caption }}" />
{% endwith %}

erl shell:

Data = [{restaurant, [{restaurant_images, [[{id, "img1"},{filekey, "foo"},{caption, "bar"}]]}]}].
test_dtl:render(Data).

output:

{ok,[[<<"\n<img src=\"/restaurant_image/">>,<<"undefined">>,
      <<"/200x200\" title=\"">>,<<"undefined">>,<<"\" />\n">>],
     <<"\n">>]}



Op woensdag 11 april 2012 22:06:51 UTC+2 schreef Evan Miller het volgende:
IIRC the required syntax is

{% with img=restaurant.restaurant_images|first %}
...
{% endwith %}

Reply all
Reply to author
Forward
0 new messages