previo | inicio

Goal: Tables should be templated


A common task for a package that manages objects is to provide an index page with a list of objects it manages and a series of actions a user can take on those objects. These are normally rendered as HTML tables.

Traditionally, such tables have been built "by hand" using the Template System's multiple tag. Recently, however, we've developed a templated list builder that makes the job much easier, and which allows for the use of a standard template that renders the resulting tables in a unified, system-wide style.

A simple example:

ad_page_contract {
    Generate a list of applications that have supporting portlets that have not
    yet been added to this portal package instance.

    @author Don Baccus (dhogaza@pacifier.com)
    @creation-date 
    @cvs-id $Id: add-applications.tcl,v 1.2 2004/02/12 21:31:21 donb Exp $
} { }

set package_id [ad_conn package_id]
set return_url [ad_conn url]
set context [list "Add Applications"]

db_1row get_portal_count {}

db_multirow -extend {add_url} applications get_applications {} {
    set add_url [export_vars -base add-applications-2 { application return_url }]
}

# Build the list-builder list
template::list::create \
    -name applications \
    -multirow applications \
    -key application \
    -bulk_actions {
        "Add checked applications" "add-applications-2" "Add checked applications"
    } \
    -bulk_action_export_vars {
        application return_url
    } \
    -elements {
        application {
            label "Application"
        }
        add {
            label Add
            link_url_col add_url
            link_html { title "Add single application" }
            display_template {Add}
        }
    }

ad_return_template