[web2py] pass a arbitrary html attributes with helpers (bootstrap data-toggle with A() for example)

502 views
Skip to first unread message

Richard

unread,
Oct 3, 2012, 12:47:20 PM10/3/12
to web...@googlegroups.com
Hello,

I would generate programmatically a bunch of links with A() helper from controller, but I fall on syntax error because of data-toggle custom bootstrap attribute (new with html5). 

Ex.: UL([ LI(A(l.upper(), _href='#tab1', _data-toggle='tab')) for l in list_of_letters_required ], _class='nav nav-tabs')

Can I pass a arbitrary argument with helpers or should I alter the helper??

Also, since this new html5 feature mean a lot of new attribute all the time what's the plan about that, we can stay behind waiting for new _Attribute get implement all the time...

Thanks.

Richard

Paolo Caruccio

unread,
Oct 3, 2012, 1:51:06 PM10/3/12
to
Please put the attribute with the hyphen in a dictionary:

UL([ LI(A(l.upper(), _href='#tab1', **{'_data-toggle':'tab'})) for l in list_of_letters_required ], _class='nav nav-tabs')

 
Instead of a set of unnamed arguments, a helper can also take a single list or tuple as its set of components using the * notation and it can take a single dictionary as its set of attributes using the **

For a deep explanation of this error please read https://groups.google.com/d/msg/web2py/ZGI7xZFPx3s/3PMwSnF-k-IJ

Richard Vézina

unread,
Oct 3, 2012, 1:44:42 PM10/3/12
to web...@googlegroups.com
Great, I thought about it, I should read the book before sorry!

Richard

On Wed, Oct 3, 2012 at 1:33 PM, Paolo Caruccio <paolo.ca...@gmail.com> wrote:
Please put the attribute with the hyphen in a dictionary:

UL([ LI(A(l.upper(), _href='#tab1', **{{_data-toggle:'tab'}})) for l in list_of_letters_required ], _class='nav nav-tabs')

 
Instead of a set of unnamed arguments, a helper can also take a single list or tuple as its set of components using the * notation and it can take a single dictionary as its set of attributes using the **

For a deep explanation of this error please read https://groups.google.com/d/msg/web2py/ZGI7xZFPx3s/3PMwSnF-k-IJ

Il giorno mercoledì 3 ottobre 2012 18:47:20 UTC+2, Richard ha scritto:

--
 
 
 

Richard Vézina

unread,
Oct 3, 2012, 1:51:19 PM10/3/12
to web...@googlegroups.com
UL([ LI(A(l.upper(), _href='#tab'+str(i), **{'_data-toggle':'tab'})) for i, l in enumerate(list_of_letters_required) ], _class='nav nav-tabs')

Only one pairs of curly brackets and the attribute needs to be quoted since it is a key dict finally...

Thanks!

Richard

Paolo Caruccio

unread,
Oct 3, 2012, 1:53:11 PM10/3/12
to web...@googlegroups.com
My fault. Original message corrected. Thank you

Richard Vézina

unread,
Oct 3, 2012, 2:29:18 PM10/3/12
to web...@googlegroups.com
:)

--
 
 
 

Christian Espinoza

unread,
Jun 14, 2013, 9:44:29 AM6/14/13
to web...@googlegroups.com
This was very useful to me too, Thanks.
Reply all
Reply to author
Forward
0 new messages