Concatenating web2py HTML Helpers

Say you want to produce something like this list of links dynamically, into an HTML page, from a web2py controller:

mobyJoe.me

 
Here is what you would put into your controller to concatenate (append) HTML Helpers:
def index():
    page_info = DIV(
                A(‘NOAA Weather’, _href=’http://mobile.weather.gov/’), BR(),
                A(‘Google Mobile’, _href=’http://m.google.com/’), BR(),
                A(‘Twitter Mobile’, _href=’http://mobile.twitter.com/’)
                )
    return dict(page_info=page_info)
 
Here is what would go into your associated view:
{{extend ‘layout.html’}}
{{=page_info}}
 
Here’s the reason. Lot’s of HTML helpers are derived from the DIV helper. According to the web2py epydocs at line 523, DIV
"Behaves like a dictionary regarding updating of attributes. 
Behaves like a list regarding inserting/appending components."
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s