Index: openacs-4/packages/acs-core-docs/www/templates.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/templates.html,v diff -u -r1.50 -r1.51 --- openacs-4/packages/acs-core-docs/www/templates.html 7 Aug 2017 23:47:52 -0000 1.50 +++ openacs-4/packages/acs-core-docs/www/templates.html 8 Nov 2017 09:42:12 -0000 1.51 @@ -1,8 +1,17 @@ -
+
By Pete Su
+</authorblurb> + +The OpenACS Template System (ATS) is designed to allow developers to cleanly separate application logic from display logic. The intent is to have all of the logic related to @@ -11,7 +20,9 @@ application in another place. This gives developer's quicker customization and easier upgrades, and also allows developers and graphic designers to work more independently. -
+
+ +
In ATS, you write two files for every user-visible page in the
system. One is a plain .tcl
file and the other is a
special .adp
file. The .tcl
file runs a
@@ -21,15 +32,26 @@
them available to the .adp
file, or the display part of
the template, which is written in a combination of HTML, special
template related tags, and data source substitutions.
-
+
+ +In the overall context of our example OpenACS Notes application, this document will show you how to set up a simple templated page that displays a form to the user for entering new notes into the system. In later sections of the DG, we'll discuss how to develop the pages that actually add notes to the database, how to provide a separate instance of the Notes application to every user and how to design appropriate access control policies for the system. -
In order for the Notes application to be useful, we have to allow users to enter data into the database. Typically, this takes two pages: one that displays a form for data entry, and another page that @@ -38,14 +60,20 @@ build the first of these pages. This isn't a very interesting use of the system since we won't be displaying much data, but we'll cover more on that end later. -
+
+ +
The .tcl
file for the form entry template is pretty
simple. Here, the only thing we need from the database is a new ID for
the note object to be inserted. Open up a file called
note-add.tcl
in the ROOT/packages/notes/www
directory, and put the following code in it:
-
+ + + ++ + ++ ad_page_contract { Form to add a note in OpenACS Notes. @@ -76,9 +104,14 @@ ad_return_template "note-add" -+
Some things to note about this code: -
+
+ +
The procedure ad_page_contract is
always the first thing a .tcl
file calls, if it's under
the www/ directory (i.e. not a Tcl library file). It does validation
@@ -103,14 +136,20 @@
properties that have been processed. By default, the template system
will look for a file by the same name as the .tcl
file
that just ran, but with an .adp
extension.
-
+
Next we write the corresponding .adp
page. This page
outputs HTML for the form, and also contains placeholders whose values
are substituted in from the properties set up by the .tcl
file. Create a file called note-add.adp
in your editor,
and insert this text:
-
+ + + ++ + ++ <master src="master"> <property name="title">@page_title;literal@</property> <property name="context_bar">@context_bar;literal@</property> @@ -129,19 +168,33 @@ </p> </form> -+
The main point to note here is: when you want to substitute a value into a page, you put the name of the data source between two "@" characters. Another point to note is the use of a master template: Master templates allow you do centralize display code that is used throughout an application in a single file. In this case, we intend to have a master template that does the standard page headers and footers for us -
+
+ +
After putting all these files into
ROOT/packages/notes/www
, you should be able to go to
/notes/
URL for your server and see the input form.
-
Templates separate application logic from display logic by requiring the developer to write pages in two stages, one file for database queries and application logic, and another for display. In OpenACS, the @@ -152,6 +205,17 @@ inserting properties into the text of the page. Later on we'll get into templates more deeply, and show how to use database queries as data sources. -
($Id$)
+ +