OpenACS Templating

An engineering goal to strive for is separation of data generation from the presentation of that data. The OpenACS templating system offers features that offer this split of data access and presentation.

  • Tcl code can create data sources using the db API (db_onerow, db_multirow)

  • The ADP page takes the data sources, and using templating tags, expresses them

  • There are simple conditional and looping structures

Tcl file:

set title "Some User Stuff"

db_multirow get_user_stuff user_stuff {
    select user_name, age, shoesize
      from my_user_table
     where name like :name_query
} {
    set user_name [encheferize $user_name]
}
ADP file:
...
<title>@title@</title>
...
<multiple name="user_stuff">
  <li> Name: @user_stuff.user_name@ is @user_stuff.age@ years old.
</multiple>
Or another interpretation:
<blink>@title@</blink>
<table border=5>

  <multiple name="user_stuff">
     <if @user_stuff.age@ le 21>
         <tr bgcolor="red">
     </if>
     <else>
         <tr bgcolor="green">
     </else>
         <td>@user_stuff.user_name@</td>
         <td>@user_stuff.age@</td>
         <td>@user_stuff.shoesize@</td>
     </tr>
  </multiple>

</table>

Intro documentation at http://openacs.org/doc/openacs-4/templates.html, http://openacs.org/doc/acs-templating/, and a tag reference can be found at http://openacs.org/doc/acs-templating/tagref/.

previous | next