OK, So I have to accept that this is not real html. I guess the best
thing for me is to enable the validation of my IDE when I am editing
html files. This is a good thing because it helps avoid errors. But
when I am done I can turn it off so I won't see the warnings and
errors that I don't need. It seems to be the best thing to do. May be
one day we will have a specific validation engine for web2py
templates.

On Mar 12, 6:51 pm, Jonathan Lundell <[email protected]> wrote:
> I see. Yes, the templates are not themselves html, and once they're parsed, 
> they're python, which gets executed to form the eventual html.
>
> I'm not sure how you'd work around that. Even if you were able to escape the 
> python code (say by enclosing it in html comment blocks (which would have to 
> be stripped off during parsing)), the template files are not in general 
> complete html, relying as they do on layout or other included files. You run 
> into the same problem with SSI; even though the SSI directives parse as html 
> comments, the .shtml files are seldom valid html.
>
> Consider something like this:
>
> <div id="{{=myid}}">
>
> I can't see an analyzer being happy with that regardless of what you did with 
> it. As it is, it has illegal characters for an id. Wrapping it in html 
> comments wouldn't help (I don't think html comments are legal in that 
> context).
>
> Would it suffice to hide the template files from the IDE? Or at least fool it 
> into treating them as plain text?
>
>
>
> > 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