Index: openacs-4/packages/acs-templating/www/doc/migration.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/doc/migration.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-templating/www/doc/migration.adp 16 Jun 2015 08:53:38 -0000 1.3 +++ openacs-4/packages/acs-templating/www/doc/migration.adp 7 Aug 2017 23:48:02 -0000 1.4 @@ -1,56 +1,71 @@ -{/doc/acs-templating {Templating}} {Templating an Existing Tcl Page} +{/doc/acs-templating {ACS Templating}} {Templating an Existing Tcl Page} Templating an Existing Tcl Page - - -

Templating an Existing Tcl Page

Templating System : Migration +

Templating an Existing Tcl Page

+Templating System + : Migration

In a Nutshell

-When templatizing a legacy tcl page, your task is to -separate code and graphical presentation. The latter goes -into an ADP file; it contains essentially HTML, augmented by a few -special tags and the \@variable\@ construct. The -code goes into a Tcl script. In other words, a templated page -consists of two files, a Tcl part that puts its results in data -sources, and an ADP page (the template), into which these data -sources will be interpolated to yield a complete HTML page. -

General

As usual, the Tcl page should start with a call to + +When templatizing a legacy Tcl page, your task is to +separate + code and graphical presentation. The +latter goes into an ADP file; it contains essentially HTML, +augmented by a few special tags and the +\@variable\@ + construct. The code goes into a +Tcl script. In other words, a templated page consists of two files, +a Tcl part that puts its results in data sources, and an ADP page +(the template), into which these data sources will be interpolated +to yield a complete HTML page. +

General

+

As usual, the Tcl page should start with a call to ad_page_contract. In its -properties block you promise the data sources that your script will provide; they were earlier called page properties, hence the name of the option. Then your script performs all the computations and queries needed to define these data sources. There are special -mechanisms for handling multirow data sources; see below.

At the end of the Tcl script, you should call -ad_return_template. The template runs after the tcl -script, and can use these data sources.

Make sure that the fancy adp parser is enabled in your AOL ini -file.

+mechanisms for handling multirow data sources; see below.

+

At the end of the Tcl script, you should call +ad_return_template. The template runs after the Tcl +script, and can use these data sources.

+

Make sure that the fancy adp parser is enabled in your AOL ini +file.

+
       [ns/server/myserver/adp]
       DefaultParser=fancy
-

A few more hints

+

A few more hints

+

Forms

+ +

Forms

+ There is nothing special about building forms; just use the -<form> tag as always. All HTML tags can be used +<form> + tag as always. All HTML tags can be used in the ADP file (template). -

A simple page

First I take a page from the news package as an example. For +

A simple page

+

First I take a page from the news package as an example. For simplicity, I pick item-view, which does not use a <form>. I reformatted it a bit to make three -panes fit next to each other and to line up corresponding code.

+panes fit next to each other and to line up corresponding code.

+
- + @@ -62,7 +77,7 @@ \@author Jon Salz (jsalz\@arsdigita.com) \@creation-date 11 Aug 2000 - \@cvs-id $Id$ + \@cvs-id $‌Id$ } { news_item_id:integer,notnull @@ -107,7 +122,7 @@ \@author Jon Salz (jsalz\@arsdigita.com) \@creation-date 11 Aug 2000 - \@cvs-id $Id$ + \@cvs-id $‌Id$ } { news_item_id:integer,notnull @@ -186,16 +201,21 @@ -
old tcl codenewold Tcl codenew
packages/news/www/item-view.tclpackages/news/www/item-view.adp

Multi-Row Data Sources

+ +

Multi-Row Data Sources

+ Technically, the result of a query that may return multiple rows is stored in several arrays. This datasource is filled by a call to -db_multirow, and the repeating part of the HTML output -is produced by the <multiple> tag. The following -example shows the part of the index page of the News +db_multirow +, and the repeating part of the HTML output +is produced by the <multiple> + tag. The following +example shows the part of the index + page of the News module that uses the mechanism, not a whole page. - + @@ -208,7 +228,7 @@ news items? \@author Jon Salz (jsalz\@mit.edu) \@creation-date 11 Aug 2000 - \@cvs-id $Id$ + \@cvs-id $‌Id$ } { } - +
old tcl codenewold Tcl codenew
packages/news/www/index.tclpackages/news/www/index.adp
 ad_page_contract {
@@ -220,19 +240,19 @@
                       news items?
     \@author Jon Salz (jsalz\@mit.edu)
     \@creation-date 11 Aug 2000
-    \@cvs-id $Id$
+    \@cvs-id $‌Id$
 } {
 } -properties {
   header:onevalue
   context_bar:onevalue
   subsite_id:onevalue
   subsite:multirow
-item:multirow
+item:multirow
   footer:onevalue
 }
 
 
..................
 append body "
@@ -247,8 +267,8 @@
     and (   expiration_date is null
          or expiration_date > sysdate)
 } {
-    append body "<li><a href=
-        \"item-view?news_item_id="\
+    append body "<li><a href="
+        \"item-view?news_item_id="\
         "$news_item_id\"
         >$title</a>\n"
 
@@ -263,13 +283,13 @@
 <p><li>You can use the <a href=
     \"admin/\">administration
     interface</a> to post a new
-    item (there's currently no
+    item (there's currently no
     security in place).
 
 </ul>
 "
 
-db_multirow item
+db_multirow item
  news_items_select {
     select news_item_id, title
     from news_items_obj
@@ -284,7 +304,7 @@
 <ul>
 
 
-<multiple name=item>
+<multiple name=item>
 
 
 
@@ -293,12 +313,12 @@
 
 
   <li><a href=
-      "item-view?news_item_id=<%
-      %>\@item.news_item_id\@"
-      >\@item.title\@</a>
+      "item-view?news_item_id=<%
+      %>\@item.news_item_id\@"
+      >\@item.title\@</a>
 </multiple>
 
-<if \@item:rowcount\@ eq 0>
+<if \@item:rowcount\@ eq 0>
   <li>There are
   currently no news items
   available.
@@ -308,14 +328,15 @@
 <p><li>You can use the <a href=
   "admin/">administration
   interface</a> to post a new
-  item (there's currently no
+  item (there's currently no
   security in place).
 
 </ul>
           
 
+ Notes:

If you have a more complicated db_foreach, where logic is + +

If you have a more complicated db_foreach, where logic is performed inside the body, then it might be helpful to build your own multirow variable. In the excert below, taken from /pvt/alerts.tcl and /pvt/alerts.adp, the foreach logic made it hard to use the db_multirow because it needed a combination of the -output from sql and also the output of tcl procedures using that -value.

+output from sql and also the output of Tcl procedures using that +value.

+
- + - + -
old tcl codenewold Tcl codenew
packages/acs-core-ui/www/pvt/alerts.tclpackages/acs-core-ui/www/pvt/alerts.adp
ad_page_contract {
-    \@cvs-id $Id$
+    \@cvs-id $‌Id: migration.html,v 1.3.2.2 2017/04/22 18:30:26 gustafn Exp $
 } {
 }
 ad_page_contract {
-    \@cvs-id $Id$
+    \@cvs-id $‌Id: migration.html,v 1.3.2.2 2017/04/22 18:30:26 gustafn Exp $
 } {
 } -properties {
     header:onevalue
@@ -358,7 +381,7 @@
 }
 
 
..................
 
@@ -540,11 +563,13 @@
           
 

+ +
+
Christian Brechbühler, Hiro Iwashima
-Last modified: $Id: migration.html,v 1.2.22.2 2014/09/09 08:32:02 + +Last modified: $‌Id: migration.html,v 1.3.2.2 2017/04/22 18:30:26 gustafn Exp $ -