On Jul 13, 3:42 am, Miguel Lopes <[email protected]> wrote:
> I think this behavior I've just found is worth sharing.
>
> Templates don't honor the if statement that conditionally "try" to include
> or exclude template blocks.
> I've just detected this (in 1.96.4 I think) and upgrade to 1.97.1 and the
> issue/behavior remains.
>
> {{rsd=None}}
> {{if rsd!=None:}}
>    {{block right_sidebar}} {{=rsd==None}} {{=repr(rsd)}} {{end}}
> {{pass}}
>
> The solution is to put the condition *inside the template block* (tested in
> 1.97.1)
> {{rsd=None}}
> {{block right_sidebar}}
>     {{if rsd!=None:}} {{=rsd==None}} {{=repr(rsd)}} {{pass}}
> {{end}}
>
> Miguel

Please do not take my critique in a bad way, but be very careful when
adding "blocks of code" in your views, I understand the example above
is just a "code sample" to illustrate a perceived deficiency in the
view templating system, but unless you are a PHP developer, this just
looks "ugly", If you have to define variables inside your views, there
most likely is a problem with the design IMO.  In the general sense,
variables _control[ler]_ program flow, please place them where they
belong, even though web2py allows this, and there is even a section
for this in the book (adding full-fledged python code inside a view
(html) page), it doesn't mean you "must" use it.

There are exceptions as always, you may need to use python code in a
view, or html code in a controller, there is nothing "wrong" with
that, but it should be that, exceptions, please do not turn web2py
into another PHP-like web development environment and further fuel
those that want to see us struggle... Thanks.

Reply via email to