{% endif %} and {% endfor %}

3,219 views
Skip to first unread message

aliane abdelouahab

unread,
Apr 10, 2013, 2:55:54 PM4/10/13
to Tornado Web Server
i was curious, how tornado makes difference when it reaches {% end %}
and know that this one is for {% for %} or for {% if %}?
why can the template be update to use endif, endfor, endwhile ...?

Lysander Trischler

unread,
Apr 10, 2013, 3:40:26 PM4/10/13
to python-...@googlegroups.com
Hi Aliane,

> i was curious, how tornado makes difference when it reaches {% end %}
> and know that this one is for {% for %} or for {% if %}?

using a stack machine https://en.wikipedia.org/wiki/Stack_machine one can
match the "end" blocks to its appropriate start blocks. And yes, if you have a
structure like this

{% if foo %}
{% for i in bar %}



{% end %}

and forget to close the "for" loop the template engine will complain about a
missing "end" for the "if" block as the given "end" block is recognized as an
"end" block for the "for" loop.


> why can the template be update to use endif, endfor, endwhile ...?

I don't understand this, but if you mean "how can …" then you have to hack the
template engine code. In contrast to Jinja or Django Tornado does not support
different end blocks.

Regards,
Lyse

Lysander Trischler

unread,
Apr 10, 2013, 3:43:09 PM4/10/13
to python-...@googlegroups.com
Hi,

> using a stack machine https://en.wikipedia.org/wiki/Stack_machine one can
> match the "end" blocks to its appropriate start blocks.

whoops, I should have read the first paragraph before posting this URL. Use
this link here instead: https://en.wikipedia.org/wiki/Pushdown_automaton

Regards,
Lyse

aliane abdelouahab

unread,
Apr 10, 2013, 4:09:22 PM4/10/13
to Tornado Web Server
thank you :D
but why there is no enfdor, endwhile..., this will make the parser
more friendly? because i run this problem when i used a lot of nested
if/for so i got a bizarre template rendering! and it was really
painful to strace them :(

On 10 avr, 20:40, Lysander Trischler <goo...@lyse.isobeef.org> wrote:
> Hi Aliane,
>
> > i was curious, how tornado makes difference when it  reaches {% end %}
> > and know that this one is for {% for %} or for {% if %}?
>
> using a stack machinehttps://en.wikipedia.org/wiki/Stack_machineone can

A. Jesse Jiryu Davis

unread,
Apr 10, 2013, 4:23:21 PM4/10/13
to python-...@googlegroups.com
I suggest using indentation very carefully to track deep nesting and avoid getting confused. Or use {# comments #} to remind yourself what block is being closed. It's useful to use {% block %} and {% include %} to factor your HTML files into smaller files.

I personally really like that I don't have to use Django-style "endfor" and "endif" with Tornado.


--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



aliane abdelouahab

unread,
Apr 10, 2013, 4:31:02 PM4/10/13
to Tornado Web Server
thank you
that what i did, i removed everything and then place them on by one!
sadly Aptana Studio dont help when it is an HTML it reads it as an
HTML so it only looks for HTML code and ignores templates, i dont know
how to add a custom tornado template.

On 10 avr, 21:23, "A. Jesse Jiryu Davis" <je...@emptysquare.net>
wrote:
> I suggest using indentation very carefully to track deep nesting and avoid
> getting confused. Or use {# comments #} to remind yourself what block is
> being closed. It's useful to use {% block %} and {% include %} to factor
> your HTML files into smaller files.
>
> I personally really like that I don't have to use Django-style "endfor" and
> "endif" with Tornado.
>
> On Wed, Apr 10, 2013 at 4:09 PM, aliane abdelouahab <alabdeloua...@gmail.com

Didip Kerabat

unread,
Apr 10, 2013, 4:35:13 PM4/10/13
to python-...@googlegroups.com
The template stack trace is pretty good nowadays, you cannot see the line number on your log file?

- Didip -

aliane abdelouahab

unread,
Apr 10, 2013, 4:56:42 PM4/10/13
to Tornado Web Server
no, there is no error, this is the problem! i've put a code where
there is:
<div class="product">
<div class="info">informations<div>
<div class="picture">informations<div>
<div>

and both info and picture uses float:left and float:right respectivly,
so because i have a lot of nested {% if %} i got a floating bizarre
images, i removed the statements and replaced them one by one, but
decided to rewrite the logic because it is getting bizarre results.

aliane abdelouahab

unread,
Apr 10, 2013, 6:40:50 PM4/10/13
to Tornado Web Server
just added a new issue asking for tornado support, it should be the
same, since it parses something, so instead of parsing <div> for
example and seeking </div> it will parse a {% for %} and seek for {%
end %}
https://github.com/aptana/studio3/issues/49
Reply all
Reply to author
Forward
0 new messages