Re: [web2py] Re: Limitation in template system
No problem be as criticl as you wish. 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.
Re: [web2py] Re: Limitation in template system
Actually I began by using functions too. But had some problems (can't remember exactly what), and view functions, even if comprised exclusively of view code didn't really tick my fancy. I much rather extract those snippets of HTML to a module or model file exclusively dedicated to html snippets. In terms of code organization I find that to be a better way of centralizing templates and such - thus making it much simpler to find them for maintenance. Actually, I recently been playing with plugin_wiki and found the same strategy applied. So you just: {{=ClassOrInstanceFromModels.whateverHTMLBlock()}} Since I mainly use blocks for sidebars I want to conditionally render two alternatives suit me: {{if renderSiderbar:}} {{=ClassOrInstanceFromModels.whateverHTMLForSideBar()}} {{pass}} Which is nice and clean. But I like to have expressed in the main layout that such sidebar may exist. Hence the using template block: {{block right_sidebar}} {{if renderSidebar: # comes from controller right ;-) }} {{=Whatever}} {{pass}} {{end}} Anyway, it is possible the best solution may depend on the situation and individual preferences. On Tue, Jul 19, 2011 at 9:26 PM, Bruno Rocha rochacbr...@gmail.com wrote: I prefer to work in the old way, used when web2py had no block in views. It is very easy and pure Python code. {{def myblock():}} html code/html code {{return}} So, in any place of views... {{=myblock()}} Obviouslly in this way you cannot have {{super}} and other cool things, but it is easy to adjust in pure Python, even using classes..
[web2py] Re: Limitation in template system
Good point, was just going to post this myself, you beat me to it. A hint should be added to the web2py book in chapter 5 http://web2py.com/book/default/chapter/05?search=block#Blocks-in-Views something like: The *{{block}} {{end}}* construction *cannot be used* inside a python condition specified by *{{if some_condition:}}*. The current implementation will ignore the condition. But you can use conditions *inside* a *{block}} *construction or use the {{def}} construction. I've added this to the web2py book as a comment. One of the editors will process this. Nico
Re: [web2py] Re: Limitation in template system
I missed that comments feature. Great you added one! Miguel On Tue, Jul 19, 2011 at 12:48 PM, Nico de Groot ndegr...@chello.nl wrote: Good point, was just going to post this myself, you beat me to it. A hint should be added to the web2py book in chapter 5 http://web2py.com/book/default/chapter/05?search=block#Blocks-in-Views something like: The *{{block}} {{end}}* construction *cannot be used* inside a python condition specified by *{{if some_condition:}}*. The current implementation will ignore the condition. But you can use conditions * inside* a *{block}} *construction or use the {{def}} construction. I've added this to the web2py book as a comment. One of the editors will process this. Nico
[web2py] Re: Limitation in template system
On Jul 13, 3:42 am, Miguel Lopes mig.e.lo...@gmail.com 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.
Re: [web2py] Re: Limitation in template system
I prefer to work in the old way, used when web2py had no block in views. It is very easy and pure Python code. {{def myblock():}} html code/html code {{return}} So, in any place of views... {{=myblock()}} Obviouslly in this way you cannot have {{super}} and other cool things, but it is easy to adjust in pure Python, even using classes.. On Tue, Jul 19, 2011 at 1:26 PM, Julio Schwarzbeck ju...@techfuel.netwrote: On Jul 13, 3:42 am, Miguel Lopes mig.e.lo...@gmail.com 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. -- -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ] [ O seu aliado nos cuidados com os animais: http://AnimalSystem.com.br ] [ Consultoria em desenvolvimento web: http://www.blouweb.com ]