conditional block insert

41 views
Skip to first unread message

Pierre

unread,
Apr 24, 2017, 9:49:04 AM4/24/17
to web2py-users
hello everyone,

{{block left_sidebar}}
{{if auth.has_membership('manager'):}}
   
{{include 'manager_sidebar.html'}}
{{else:}}
   
{{include 'sidebar.html'}}
{{pass}}
{{end}}

for some reason this doesn't work. It inserts a mixture of the two sidebars. If i move blocks inside of the if same problem....?? there seems to be a conflict between the two includes ?

Richard Vézina

unread,
Apr 24, 2017, 10:22:10 AM4/24/17
to web2py-users
Hello Pierre,

Simplify your code... Remove the if and try one side bar at a time first... You may find that they are not properly constructed... I mean, the code above seems fine... So I suspect that it is the way you construct your side bar that are causing your issue. There is maybe another issue, as I am not so familiar with web2py view "block" instruction... I suggest you reading here : http://web2py.com/books/default/chapter/29/05/the-views#Blocks-in-views

If your side bar are correct in there original view ("manager_sidebard" and "sidebar"), I would suspect that if inside block can't be properly treated for some reason...

But you could probalby simplified your code and have only once sidebar view which already containt the proper side bar stuff as you only display one or the other base on user membership, you surely don't need 2 views for that if you move your if inside sidebar.html controller or view and filter things out there...

Good luck

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Áureo Dias Neto

unread,
Apr 24, 2017, 10:27:55 AM4/24/17
to web...@googlegroups.com
is all python code, you can use one '{{' at the begin of code and '}}' at end

Anthony

unread,
Apr 24, 2017, 3:17:24 PM4/24/17
to web2py-users

No, {{block}} and {{include}} are not Python code but special template directives, so you cannot write the code as you have above.

In general, it's a good idea if you try things out yourself before suggesting them as solutions.

Anthony

Anthony

unread,
Apr 24, 2017, 3:18:22 PM4/24/17
to web2py-users
In general, that approach should work, so you'll have to show your code for further diagnosis.

Anthony

Pierre

unread,
Apr 24, 2017, 4:40:33 PM4/24/17
to web2py-users
found the bogue.....a nasty supernumerary {{pass}}  in the sidebar.html

thank you  guys for your patience and perseverence.......



Reply all
Reply to author
Forward
0 new messages