Chapter 7: Page Generation


Template File Support

WEB·FM 4.0 introduces support for easy-to-use Template files. Template files are Internet standard HTML documents void of confusing, incompatible, and proprietary markup [/tags]. For this reason a webmaster need not learn yet another markup language, and Template documents are fully compatible with all existing web page editors and client browsers.

A highly intelligent parsing algorithm in WEB·FM automatically selects appropriate pop-up/pull-down menu items and automatically checks appropriate radio button or checkbox fields in a Template document using database record information. A single context-sensitive [field name] token may be used throughout a Template document to dynamically insert cell data where desired, auto-populate pop-up/pull-down menus, and auto-replicate radio button and checkbox fields from database value lists, all with no tags required!

Example Template:

Template files must reside in the web server directory specified by the current request URL. Template file names must end with a ".html" suffix. When referred to with the HTML variable, the ".html" suffix is a flag for WEB·FM to look in the current directory for the Template file and perform database field and value list substitutions. Selection of existing pop-up menus, checkboxes, and radio buttons in a Template document are automatic.

Example URL:

IMPORTANT Template files may only be used when returning information from a single database record.

[Tokens] are considered place holders for substituting dynamic data. Square [brackets] surrounding a [field name], [search field], [variable], or other [value] help WEB·FM perform dynamic substitutions (i.e. server-side includes). [Field Name] tokens are context-sensitive. That is, where [field name] tokens are used in a Template file influences substitution behaviour. By itself, a [field name] token is replaced with raw cell data from the found record.

When present in a pop-up/pull-down menu, [field name] will auto-populate menu items using values from a database value list assigned to that field name on the target layout. When flush against an HTML checkbox or radio button, WEB·FM replicates the INPUT element with "<BR>" delimiters for each item in the field's value list. The actual NAME attribute of pop-up menus, checkboxes, and radio buttons is irrelevant as far as substitutions are concerned.

Syntax Examples:

Dynamic database [field name] substitutions:

[field name]

Dynamic population of pop-up menus and scroll lists:

<OPTION>[field name]

Dynamic replication of checkboxes and radio buttons:

<INPUT TYPE="checkbox" NAME="field name" VALUE="">[field name]

IMPORTANT Dynamic population of pop-up menus and dynamic replication of checkboxes or radio buttons requires the field on the target layout be formatted with a database value list.

Portal Fields

WEB·FM supports a custom <portal> tag for dynamic replication of enclosing HTML for each portal row of a relational field on a layout. Template files with [portal field] tokens require this tag so WEB·FM can replicate portal rows using the desired HTML data. Both [field name] and [portal field] tokens are legal inside the <portal> tag.

Remember from a previous chapter that relational fields must be referred to by a special name that begins with the name of the database relationship, followed by two colons "::" and the actual field name.

Syntax Example:

<portal><LI>[relationship::field name]<P></portal>

Error Template Files

The Error variable supports Template files in a similar fashion as the HTML variable. However, rather than [field name] tokens we use [search field] tokens instead. WEB·FM will select appropriate pop-up/pull-down menu items and automatically check appropriate radio button or checkbox fields in a Template file using submitted find field criteria. The [search field] token may be used throughout a Template document to dynamically insert cell data where desired. WEB·FM uses submitted FORM arguments for field substitutions when an unsuccessful Find returns no found records.

Understanding [Token] Support

[Tokens] are considered place holders for substituting dynamic data. Square [brackets] surrounding a [field name], [search field], [variable], or other [value] help WEB·FM perform dynamic substitutions (i.e. server-side includes) in the Template file for dynamic page generation.

Outgoing server-side include substitution [tokens]

[RecID]
The unique ID for a record maintained internally by the database. Limited to one [RecID] token per record.
[found]
An integer value for the number of records found.
[values]
A text string of query values with comma delimiters.
[fields]
A text string of query fields with comma delimiters.
[date]
The current date.
[start]
The first record number currently displayed in the found set.
[end]
The last record number currently displayed in the found set.
[max]
The integer value for total number of records displayed.
[range]
The first and last record number for the next set of found records.
[page]
The current page number.
[pages]
The total number of pages (influenced by [max]).
[database]
The current database name.
[layout]
The current database layout.
[sort]
Value of current Sort variable.
[sortorder]
Value of current SortOrder variable.
[script]
Value of current DoScript variable.
[html]
Value of current HTML variable.
[field name]
Database cell value.
[portal field]
Database relational field value.
[search field]
Query field value.

Example:

Page [page] Results: [start] - [end] of [found] found by [sort]

Understanding <Tag> Support

<next></next> Custom tag for inserting a link to the next subset of found records. <prev></prev> Custom tag for inserting a link to the previous subset of found records. <portal></portal> Custom tag in Template files for replication of portal rows.

Example:

<next>Next [max] Results ([range])</next>

Calculation Formulas, Functions and Uses

WEB·FM 4.0 relies partly on Template files and partly on database calculation fields to dynamically build and deliver HTML documents for publication on the web. Template files are easier to use and design, but HTML calculation fields can be far more powerful. In the case of calculation fields, WEB·FM's job is to grab HTML from these fields and serve them to the web browser. By using a calculation field you have complete control over the HTML formatting of your documents, including direct access to over 100 powerful calculation functions supported by FileMaker Pro. Keep in mind that only the "html" calculation field is required for the purpose of returning 2 or more found records. Refer to Chapter 3: Getting Started for a short tutorial on creating calculation fields that build HTML documents. Using calculation fields will also offer slightly better performance.

USEFUL FUNCTIONS

If (test, resultÊone, resultÊtwo) IsEmpty (field) GetRepetition (repeatingÊfield, number) PatternCount (text, searchÊstring) Substitute (text, searchÊstring, replaceÊstring) NumToText (number) DateToText (date) Status (CurrentDate) Status (CurrentTime) Status (CurrentRecordNumber)

Returning a Random Banner

Here's a useful technique for cycling through a set of custom headers with each and every WEB·FM database transaction. This technique might be used, for example, to show a different advertiser on each and every database hit, or change the background color of an HTML page randomly.

  1. Create a field in your database named "header" of type "calculation".
  2. Set the Storage Options for this field to NOT store results and to "evaluate only when needed".
  3. Use the Choose and Random functions as shown below to dynamically return a different result each time the calculation evaluates.

    In this example, we're returning a random image from a selection of 5 different choices. Any database hit that uses the Header variable, the formula will evaluate each time to generate a different result. The Find and FindAll commands, remember, have a default to return the "header" field automatically if it exists.

    "<IMG SRC=""" & Choose(NumToText(Int(Random*10)), "zero.gif","first.gif", "second.gif", "third.gif", "fourth.gif", "zero.gif","first.gif", "second.gif", "third.gif", "fourth.gif") & """>"

    Expiring HTML Documents

    This formula for expiring HTML is useful for protecting private information from hackers, but momentarily making the information available to the person who creates a record.

    If(Status (CurrentDate) = CreateDate and Status(CurrentTime) - CreateTime ² Time(0, 0, 5), "html with private password", "unauthorized")