On Monday, October 10, 2011 4:03:49 PM UTC-4, miroslavgojic wrote:
>
> with
> {{=request.url}}
> i will get
> /some/my/url/address
>
> but when I tray next example it is not working:
>
> {{
> myurl = request.url:
> i = /some/my/url/address:
> if i == myurl:
> response.writ('my first HTML output')
> else:
> response.write('my other HTML output')
> pass
> }}
>
> how to resolve this, I need one part layout.htm to be different for index
> page than an other pages, is there some other solutions
>
How about using a
block: http://web2py.com/book/default/chapter/05#Blocks-in-Views? Define the
default content of the block in layout.html, and define the index specific
content in index.html.
A few other points:
- I believe request.url will contain the rewritten version of the
requested URL if you're using routes.py, so it may not match your hand-coded
URL.
- If you need to determine the current function (and/or controller), it's
better to match request.function (and/or request.controller) rather than
trying to match the full URL (which could get tricky if the are args, a
query string, or any rewrites going on).
- Using response.write is generally discouraged and usually unnecessary
-- instead, just do:
{{if condition:}}
your html goes here
{{else:}}
alternative html goes here
{{pass}}
Anthony