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.2.6 -r1.3.2.7 --- openacs-4/packages/acs-templating/www/doc/migration.adp 21 Aug 2015 10:49:22 -0000 1.3.2.6 +++ openacs-4/packages/acs-templating/www/doc/migration.adp 25 Aug 2015 18:02:10 -0000 1.3.2.7 @@ -2,31 +2,40 @@ {/doc/acs-templating {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 +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 +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 +

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

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

+
@@ -186,12 +200,17 @@ -
old tcl codenew

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. @@ -316,6 +335,7 @@
+ 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.

+value.

+
@@ -540,11 +562,13 @@ -
old tcl codenew

+ +
+
Christian Brechbühler, Hiro Iwashima
+ Last modified: $Id: migration.html,v 1.3 2014/10/27 16:40:14 victorg Exp $ -