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 @@
- 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
+ As usual, the Tcl page should start with a call to
At the end of the Tcl script, you should call
- Make sure that the fancy adp parser is enabled in your AOL ini
-file.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
\@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
+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.ad_return_template
. The template runs after the tcl
-script, and can use these data sources.
+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
+ns_puts
, ns_write
etc., which don't wait
-till the headers are written or the page is completed; they may act
-differently than you expect.<%
-%>
in the adp page.ns_puts
, ns_write
etc., which don't
+wait till the headers are written or the page is completed; they
+may act differently than you expect.<%
+%>
in the adp page.<include>
d from several pages.
-Prefer this to writing a tcl proc that returns HTML.-Nuts \$2.70 \[<a href=\"shoppe\">buy</a>\] +Nuts \$2.70 \[<a href="\"shoppe\">buy</a>\]
<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).
-First I take a page from the news package as an example. For +
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.
old tcl code | new | +old Tcl code | new | ||
---|---|---|---|---|---|
packages/news/www/item-view.tcl | packages/news/www/item-view.adp |
||||
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.
old tcl code | new | +old Tcl code | new | ||
---|---|---|---|---|---|
packages/news/www/index.tcl | packages/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> |
<if>
construct to handle
@@ -324,26 +345,28 @@
documentation.db_multirow
does have a code block and an
optional if_no_rows
block, just like
-db_foreach
. They aren't used in the example,
+db_foreach
. They aren't used in the example,
though.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.
old tcl code | new | +old Tcl code | new | ||
---|---|---|---|---|---|
packages/acs-core-ui/www/pvt/alerts.tcl | packages/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 @@ |