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 -N -r1.53 -r1.53.2.1 --- openacs-4/packages/acs-core-docs/www/templates.html 4 Dec 2018 13:30:31 -0000 1.53 +++ openacs-4/packages/acs-core-docs/www/templates.html 2 Mar 2019 19:30:06 -0000 1.53.2.1 @@ -1,17 +1,8 @@ -Using Templates in OpenACS

Using Templates in OpenACS

- - - -<authorblurb> -

By Pete Su

-</authorblurb>
- -

Overview

- - - -

+Using Templates in OpenACS

Using Templates in OpenACS

By Pete Su

+ OpenACS docs are written by the named authors, and may be edited + by OpenACS documentation staff. +

Overview

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 @@ -20,9 +11,7 @@ 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 @@ -32,26 +21,15 @@ 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. -

- - -
- -

Entering Notes

- - - -

+

Entering Notes

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 @@ -60,20 +38,14 @@ 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.
@@ -104,14 +76,9 @@
 
 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 @@ -136,20 +103,14 @@ 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>
@@ -168,33 +129,19 @@
 </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. -

- - -
- -

Summary

- - - -

+

Summary

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 @@ -205,17 +152,6 @@ 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. -

- -
- -

Documentation

- -

+

Documentation

Templating system documentation -

-

($Id$)

- -
- -
+

($Id$)