I agree that that is what it should do. Please open a ticket about this.
On Mar 4, 11:20 am, Jonathan Lundell <[email protected]> wrote: > On Mar 4, 2011, at 1:52 AM, szimszon wrote: > > > > > > > > > > > > > web2py™ Version 1.92.1 (2011-02-16 15:04:40) > > Python Python 2.5.2: /usr/bin/python > > > Traceback (most recent call last): > > File "/home/szimszon_nfs/web2py/gluon/restricted.py", line 186, in > > restricted > > ccode = compile2(code,layer) > > File "/home/szimszon_nfs/web2py/gluon/restricted.py", line 173, in > > compile2 > > return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, > > 'exec') > > File "/home/szimszon_nfs/web2py/applications/serveradmin/views/ > > integrity/ftp.html", line 123 > > pass > > ^ > > SyntaxError: invalid syntax > > > if msg: > > response.write('\n<h2>', escape=False) > > response.write(T("Commands executed")) > > response.write('</h2>\n', escape=False) > > response.write(XML(msg) > > pass > > > My template was working until now (I don't know exactly from what > > web2py version is it bad). > > > My template was: > > > {{if msg:}} > > <h2>{{=T("Commands executed")}}</h2> > > {{ =XML(msg) > > pass > > try: > > dname=request.args[1] > > except: > > dname=0 > > pass > > editname=T('New')}} > > Thadeus might want to chime in here if I have the details wrong (there really > ought to be a formal reference for template syntax; the tutorial in the book > is nice, but not complete). > > There's a subtle difference in template parsing when =something appears at > the beginning of an escaped block (where "beginning" ignores white space, so > =XML above is regarded as being at the beginning of the code block). > > You probably know already that =something is translated to > response.write(something). But the question arises, what exactly is > "something"? That is, where does it end? > > And when the '=something' is found at the beginning of a code block, > 'something' is defined to be *everything until the end of the code block*. > > When '=something' is found *embedded* in a code block (not at the beginning, > ignoring white space), then the end of 'something' is either the next newline > or the end of the code block, whichever comes first. > > So (to shorten up the problem here), you've effectively got this: > > {{=msg > pass}} > > ...which becomes: > > response.write(msg > pass) > > ...and Python is going to object. > > On the other hand, if you had written: > > {{if xyz: > =msg > pass}} > > The output will be: > > if xyz: > response.write(msg) > pass > > ...and everybody's happy. Because =msg wasn't the first thing in the code > block, only msg gets included in the response.write argument. > > Is there a good reason for =something to be interpreted two different ways? > I'm not sure it's intentional. Thadeus? Massimo? > > > > > > > > > > > Now I had to modify: > > > {{if msg:}} > > <h2>{{=T("Commands executed")}}</h2> > > {{ =XML(msg)}} < ----- > > {{pass <----------- > > try: > > dname=request.args[1] > > except: > > dname=0 > > pass > > editname=T('New')}}

