tip of the day: icons in menu

67 views
Skip to first unread message

mdipierro

unread,
Sep 14, 2009, 2:00:30 AM9/14/09
to web2py-users
In web2py you create a menu like

response.menu=[['Title',False,URL(...),[]]

where [] is a submenu.

You place an icon close to the title by doing

response.menu=[[TAG[''](IMG(_src=icon,'Title'),False,URL(...),[]]

where icon is the url of the icon.

Thadeus Burgess

unread,
Sep 15, 2009, 10:29:52 AM9/15/09
to web...@googlegroups.com
I was just about to ask about this, thanks!


-Thadeus

Jonathan Lundell

unread,
Sep 15, 2009, 11:02:03 AM9/15/09
to web...@googlegroups.com

The syntax of both these lines looks a little suspect (counting
brackets, anyway).

Maybe you could add a word or two about using TAG this way, too?

Thadeus Burgess

unread,
Sep 15, 2009, 11:05:57 AM9/15/09
to web...@googlegroups.com
Yes the syntax is incorrect.

[TAG[''](IMG('Overview', _src=URL(r=request, c='static', f='images/overview.png'))), False, URL(request.application, 'default', 'index')],

Provides
Traceback (most recent call last):
File "/home/thadeusb/Applications/web2py/gluon/restricted.py", line 178, in restricted
exec ccode in environment
File "/home/thadeusb/Applications/web2py/applications/init/models/menu.py", line 49, in <module>
[
TAG[''](IMG('Overview', _src=URL(r=request, c='static', f='images/overview.png'))), False, URL(request.application, 'default', 'index')],
File "/home/thadeusb/Applications/web2py/gluon/html.py", line 307, in __init__
% self.tag
SyntaxError: <img/> tags cannot have components

And

[TAG[''](IMG(_src=URL(r=request, c='static', f='images/overview.png'),'Overview')), False, URL(request.application,'default','index')],

Provides

Traceback (most recent call last):
File "/home/thadeusb/Applications/web2py/gluon/restricted.py", line 176, in restricted
ccode = compile(code.replace('\r\n', '\n'), layer, 'exec')
File "/home/thadeusb/Applications/web2py/applications/init/models/menu.py", line 50
[TAG[''](IMG(_src=URL(r=request, c='static', f='images/overview.png'),'Overview')), False, URL(request.application,'default','index')],
SyntaxError: non-keyword arg after keyword arg


-Thadeus

Thadeus Burgess

unread,
Sep 15, 2009, 11:09:12 AM9/15/09
to web...@googlegroups.com
Perhaps you ment:


[TAG[''](IMG(_src=URL(r=request, c='static', f='images/overview.png'), 'Overview')), False, URL(request.application, 'default', 'index')],

This gives the desired functionality

Is there any way to center the icon over the text?

-Thadeus

Thadeus Burgess

unread,
Sep 15, 2009, 11:26:32 AM9/15/09
to web...@googlegroups.com
Solution to center icon over text

Wrap the text in XML() so that it looks like this

...erview.png'), XML('<br />Overview')), Fal...

-Thadeus
Reply all
Reply to author
Forward
0 new messages