I am sorry Jonathan, I think we have a misunderstanding. All this
works with web2py. The problem is that characters "<" and ">" need to
be escaped in html. Otherwise, it is not html. The html produced by
web2py is well formed but in the template itself the html it is not
well formed. Because of this, the templates are not using well formed
html all the times and the html code analyzer of my IDE is given me
errors.

On Mar 12, 3:11 pm, Jonathan Lundell <[email protected]> wrote:
> On Mar 12, 2011, at 11:54 AM, Jonathan Lundell wrote:
>
>
>
> > On Mar 12, 2011, at 11:39 AM, pierreth wrote:
>
> >> I think you mean the response object.
>
> > Yes, response.
>
> >> The example code you gave still
> >> use the character "<" so it does not help.
>
> > Did you try it? How about the second version?
>
> Hmm. I take back what I said earlier: all versions work for me, including 
> your original one.
>
> In what context are you using the expression?
>
>
>
> >> In fact, the problem is that web2py is not processing the xml document
> >> but it parse directly the html file. I would really like Massimo to
> >> fix this.
>
> >> On Mar 12, 2:15 pm, Jonathan Lundell <[email protected]> wrote:
> >>> On Mar 12, 2011, at 11:05 AM, pierreth wrote:
>
> >>>> Hello,
>
> >>>> I have small problem when the characters "< and ">" are used in web2py
> >>>> html template views. Using them for Python breaks the html:
>
> >>>> {{="OK" if x < 0 else "bad"}}
>
> >>>> Because these characters are not escaped in the code, the html file is
> >>>> no longer well formed.
>
> >>>> Using the html entities "&lt;" and "&gr;" does not solve the problem
> >>>> because web2py gives an error when theses characters are used as
> >>>> Python code in templates.
>
> >>>> Is it possible to fix this to have well formed html for web2py
> >>>> templates?
>
> >>> This is a consequence of the way the '=' (request.write) operator behaves 
> >>> at the beginning of a code block: it treats the entire string as its 
> >>> argument string, something like: request.write('"OK" if x < 0 else "bad"')
>
> >>> You can rewrite it to use request.write explicitly, or to put each = 
> >>> operator on its own line.
>
> >>> {{request.write("OK" if x < 0 else "bad")}}
>
> >>> or
>
> >>> {{if x < 0:
> >>> ="OK"
> >>> else:
> >>> ="bad"
> >>> pass
>
> >>> }}
>
> >>> (I think)
>
> >>> When the '=' operator is embedded in a code block, it consumes everything 
> >>> until the end of the physical line or code block, whichever comes first. 
> >>> When it begins a code block, it consumes the entire block.
>
>

Reply via email to