See http://web2py.com/books/default/chapter/29/05/the-views#HTML-helpers,
in particular:
Notice that helper attributes are passed as keyword arguments to the
helper. In some cases, however, attribute names include special characters
that are not allowed in Python identifiers (e.g., hyphens) and therefore
cannot be used as keyword argument names. For example:
DIV('text', _data-role='collapsible')
will not work because "_data-role" includes a hyphen, which will produce a
Python syntax error.
In such cases you have a couple of options. You can use the data argument
(this time without a leading underscore) to pass a dictionary of related
attributes without their leading hyphen, and the output will have the
desired combinations e.g.
>>> print DIV('text', data={'role': 'collapsible'})<div
>>> data-role="collapsible">text</div>
or you can instead pass the attributes as a dictionary and make use of
Python's ** function arguments notation, which maps a dictionary of
(key:value) pairs into a set of keyword arguments:
>>> print DIV('text', **{'_data-role': 'collapsible'})<div
>>> data-role="collapsible">text</div>
Anthony
On Monday, December 5, 2016 at 2:36:01 AM UTC-5, lyn2py wrote:
>
>
> Hello guys! Long time no see :)
>
> With HTML5 attributes being widely used, I thought I could add one to the
> response.menu
>
> I tried but it didn't work, I appreciate help and pointers! =)
>
> This is the current response.menu generated HTML (specifically, the
> *first* ul):
>
> <ul class="nav navbar-nav">
> ...
> ...
> ...
> </ul>
>
>
> This is the result I would like to attain:
>
> <ul class="dropdown menu" data-dropdown-menu>...
> ...
> ...
> </ul>
>
>
>
> It's easy to change the class. But how to I add the HTML5 attribute?
>
>
> Kindly note that it is simply "data-dropdown-menu" without any "=".
>
>
> Thank you!
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.