Components for web2py HTML pages NOT derived from layout.html

I wrote a post to the google web2py-users group on this subject. This WordPress post will be my log of the work i am doing on this subject.

Here is a copy of my original web2py-users group post.

Dear web2py Forum,

Often i find myself making View pages that are NOT derived from layout.html and yet wanting to include some aspects of its capabilities.

I thought the web2py “Component” concept might help to deliver a modular approach.

My initial thoughts would be to pair small CSS files and HTML Component definitions for the following:

  • menu
  • login/register
  • left sidebar
  • right sidebar
  • footer
  • ajax
  • flash response
  • mobile
  • responsive

while maintaining a list of dependencies among them.

Has anyone thought about this granular approach before?

I would not want to use a Wizard for this, because in my experience, the generated code is unfamiliar to me and difficult to customize.

Thanks for a GREAT framework.

Love and peace,

Joe

1. i looked up web2py component

By def it seems that components

communicate with the component controller function via Ajax

Therefore the list of dependencies must contain ajax stuff.

2. add a new component to list:

navbar – is a complex component containing both menu and auth login stuff

 

#components, #css, #gui, #html-helpers, #idioms, #web2py

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."
 

#html-helpers, #web2py