Chapter 3 Working with Dynamo Web Sites
Templates in a PowerDynamo Web site are HTML documents that may include embedded instructions. This section describes how to create, edit, and delete Dynamo templates.
For information about scripts, which are the other kind of dynamic Web content managed by PowerDynamo, see "Writing DynaScripts".
This section describes how to add a template to your Web site. The example describes a template displaying a table of information about current products sold by the company.
To create a template:
You can view the contents of the template in several ways, as described in "Viewing and editing templates".
The Add Template wizard provides you with a list of formats to choose from.
<DL>
<DT>Otley
<DD>A market town in Wharfedale
<DT>Wharfedale
<DD>A valley in Yorkshire, U.K.
</DL>
You can view and edit templates in several ways from within Sybase Central and from a Web client:
To view or alter the source of a template:
You can check that your query result contains the data you expect by viewing the output in the Sybase Central editor.
To view the output HTML of a template:
You can check that your query result contains the data you expect without leaving Sybase Central, and check the formatting of a template, by viewing the output in your Web browser.
To view template output in a browser:
Limitations of browsing output
The document output is sent to a
file, which is then loaded into your Web browser. Consequently,
any links to relative addresses will not work, and any graphics
that are given relative addresses are not displayed. It is recommended to
use relative addresses and tolerate the discrepancies in output
appearance when accessed in this manner. To view output exactly
as it would appear to a user, use the Personal Web Server with a
browser.
Web authoring tools (HTML editors) work with HTML files, while PowerDynamo templates are stored in a database. However, you can edit PowerDynamo templates using a Web authoring tool.
This tutorial shows you how to customize the formatting of the template that you generated in the previous tutorial. You must have a Web authoring tool other than the Sybase Central editor.
To edit a template using a Web authoring tool or text editor:
<!--data-->
Instructions are embedded in a template as HTML comments rather than as HTML tags.
A SQL statement is contained inside an HTML comment. HTML comments are of the following form:
<!-- this is a commment -->
All material inside the angle brackets is ignored by an HTML parser such as that included inside a Web client. Thus, a Web client can view a template, and it will ignore the material inside the comment tags. If you edit the template using an HTML authoring tool it will ignore the embedded instructions. Of course, the SQL statements are not seen by a Web client, as they are interpreted and executed by the PowerDynamo Application Server.
SQL statements are embedded in an HTML document as follows:
<!--SQL
sql-statement
-->
The SQL statement itself can continue over several lines. It should start on a separate line from the SQL comment tag.
The following HTML fragment contains a simple query.
<!--SQL
SELECT name, color, size, unit_price
FROM "dba".product
-->
You can provide an identifying name for an embedded query. This is useful, for example, if you have more than one SQL statement in a template.
To name a SQL statement, provide a name for a SQL statement as the NAME attribute for the SQL comment tag. The following SQL statement has a name of ProductQuery:
<!--SQL NAME=ProductQuery
SELECT name, color, size, unit_price
FROM "dba".product
-->
The SQL statement itself must start on a separate line from the NAME attribute.
If the embedded SQL statement is a query, then the Application Server inserts the results of the query into the output document. PowerDynamo allows you to describe the formatting of a query using a formatting comment tag.
The HTML tags for formatting instructions are slightly different from the tags used for SQL statements. To allow an HTML editor to modify and refine the actual formatting, the formatting description is not inside a comment. Instead, comment tags are used for placeholders for the data, which are replaced on processing by the actual data.
All data placeholders must be between formatting start and end comment tags. The formatting start comment tag is of the form
<!--FORMATTING-->
The formatting end comment tag is of the form
<!--/FORMATTING-->
Formatting using scripts
In addition to using formatting comment
tags, you can use embedded scripts to format output. The flexibility
of scripts allows more varied formatting than the formatting comment
tags.
As these are HTML comments, there is no restriction on the HTML that can be included between the tags. The formatting comment tags have no effect on HTML that occurs between them; they affect just the embedded instructions.
For more information on Dynamo Tags, see the chapter "Dynamo Tags" in PowerDynamo Reference.
You can use text replacement macros, or text substitution macros, to include values provided by a Web client in document output. For example, a document in your Web site may ask a user to enter their name in an HTML form. Their name can then be used in documents returned from the Web server.
This example includes the following:
To create the documents for the example:
<HTML>
<HEAD>
<TITLE>
Test of text substitution
</TITLE>
</HEAD>
<BODY>
<FORM ACTION="reply.stm" NAME="log" METHOD="GET">
<p>Please enter your name.
<ul>
<li>First name:
<INPUT TYPE="text" NAME="firstname" SIZE="15">
<li>Last name:
<INPUT TYPE="text" NAME="lastname" SIZE="15">
</ul>
<p><Center>
<INPUT TYPE="Submit" VALUE="Register">
</Center></p>
</FORM>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Test of text substitution</TITLE>
</HEAD>
<BODY>
<p>Dear $firstname $lastname,</p>
<p>Thank you for using our text substitution facility.
<p>
Yours
<p>
TextSub Corporation.
</BODY>
</HTML>
To run the example:
http://localhost/Site/form.stm
http://localhost/Site/reply.stm?firstname=first-name&lastname=last-name
Dear Simon James,
Thank you for using our text substitution facility.
Yours
TextSub Corporation.
Text replacement macros can be accessed inside scripts, but are accessed in a different manner. The argument is a property of the document object, which is a predefined object. The actual value of an argument named firstname can be accessed inside a script as:
document.value.firstname
For information about using text replacement macros in scripts, see "Passing variables from one document to another".
Copyright © 1999 Sybase, Inc. All rights reserved. |