FlexSearch Template Merge

Having a data file is nice, but we need to present the information, FlexSearch uses templates to display data. A template is an HTML page that contains imbedded data file field references, FlexSearch replaces these references with the values of the fields. A field reference is the name of the field surrounded by "#" symbols, for instance #Year# or #Make#. Additionally, FlexSearch maintains a series of system fields.  The basic system fields are:

System_Name: The name of the licensed system owner
Date: The system date
Time: The system time
Record_Number: The record number of the current row
Script: The full path to FlexSearch

Later we will cover additional system fields that are used only complex templates.

Single Record Forms:

The simplest type of template is a single record form, it can be used to display fields from one record in a data file.

Example 1: This is a simple form that will display several fields in a very simple form:

   <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
   <html>
   <head>
   <title>Paul's Used Car Sample</title>
   </head>
   <body>
   <h1>Paul's Used Car Sample</h1>
   Year: #Year# <br>
   Make: #Make#
   Model: #Model#<br>
   </body>
   </html>

When FlexSearch merges this template with the data file and it is viewed in a browser, it looks like this:

Paul's Used Car Sample

Year: 1996
Make: Infiniti
Model: I30

While this form is very simple, it begins to give you an idea of what is possible.

Example 2: Watch closely what happens in this example, since the stock number is a unique field, we can make a directory of images files and use the stock number as filename of an image. Lets take the example from above, and add this line:

   <img src="/Cars/images/#Stock_No#.JPG" width="200"height="75">

When this line is merged with the data file and displayed this is the result:

Paul's Used Car Sample

Year: 1996
Make: Infiniti
Model: I30
23481.JPG (8211 bytes)

 

By having multiple directories of image files we can have multiple views of the car. This same type of creative use of the data field tags can be used to select sound bytes, midi files and even full motion video.

Output Suppression

Sometimes it is useful to have a section of a template not appear when certain conditions in the data are not met.  For instance suppose we added fields to indicate air conditioning, Cassette, CD player and cruise control.  For each of these we create a small JPG file to show an icon on the form.

AC:wpe59.jpg (1137 bytes) CD:wpe56.jpg (1177 bytes) Cassette:wpe57.jpg (1002 bytes) Cruise:wpe58.jpg (1099 bytes)

If we just tried to have a field that contained an image name, we would get broken image links every time the field was blank.   Not to mention that we would spend lots of time filling out field s with image names when they do exist.  There is a much easier way. Lets make the fields "A/C" "Cassette", "CD" and "Cruise", in each field we place a 'Y' if the option exists on the car, otherwise we leave it blank.  The we enhance the form with:

<!-- FlexSearch Suppress-Start #A/C# -->
<img src="/Cars/icons/AC.jpg" width="20" height="20">
<!-- FlexSearch Suppress-Stop -->
<!-- FlexSearch Suppress-Start #Cassette# -->
<img src="/Cars/icons/Cassette.jpg" width="20" height="20">
<!-- FlexSearch Suppress-Stop -->
<!-- FlexSearch Suppress-Start #CD# -->
<img src="/Cars/icons/CD.jpg" width="20" height="20">
<!-- FlexSearch Suppress-Stop -->
<!-- FlexSearch Suppress-Start #Cruise# -->
<img src="/Cars/icons/Cruise.jpg" width="20" height="20">
<!-- FlexSearch Suppress-Stop -->

Each One of these Suppression blocks will evaluate the field if it is blank the section will not be output to the browser.  If the field is not blank the image will be included.  Suppose our Infinity has AC, CD and Cruise:

Paul's Used Car Sample

Year: 1996
Make: Infiniti
Model: I30
23481.JPG (8211 bytes)wpe59.jpg (1137 bytes)wpe56.jpg (1177 bytes)wpe58.jpg (1099 bytes)

Multiple Record Forms

Single record forms are nice, but when working with data files, it is usually much more interesting to view more than one record at a time. FlexSearch has the ability to show you more than one record at a time. To do this you mark a section of the template file for multiple records, FlexSearch will repeat that section of the template for each an every record in the query selection.

At the beginning of the section of the HTML file that you want to repeat insert and HTML comment that reads "FlexSearch Multi-Record-Start" in the html it looks like:

   <!-- FlexSearch Multi-Record-Start -->

At the end of the section to be repeated insert a second HTML comment "FlexSearch Multi-Record-Stop" in html it looks like:

   <!-- FlexSearch Multi-Record-Stop -->

Example 3: This is a simple organization of fields in a table which includes a thumbnail image on each row in the table.

   <table border="1" cellpadding="5" cellspacing="2">
      <tr>
         <th>Link </th>
         <th>Stock_No </th>
         <th>Year </th>
         <th>Make </th>
         <th>Model </th>
         <th>Category </th>
         <th>Price </th>
         <th>Picture</th>
      </tr>
      <!-- FlexSearch Multi-Record-Start -->
         <tr>
            <td><a href="#View_Link#">Detail</a> </td>
            <td>#Stock_No# </td>
            <td>#Year# </td>
            <td>#Make# </td>
            <td>#Model# </td>
            <td>#Category# </td>
            <td>#Price# </td>
            <td>
               <a href="#View_Link#">
                  <img src="/cars/thumnails/#Stock_No#.JPG" 
                     width="60" height="40" alt="Thumnail">
               </a>
            </td>
         </tr>
      <!-- FlexSearch Multi-Record-Stop -->
   </table>

If you were paying close attention, you will also have noticed the #View_Link# field, this is an additional system field that gets created when FlexSearch is processing multiple record templates. It contains all of the information to display the specific record that is being displayed in the current row of the table. Meanwhile here is what it looks like:

Link Stock_No Year Make Model Category Price Picture
Detail 27237 1996 Dodge Neon Sport Small Coupe $7,500 Thumnail
Detail 24767 1996 Dodge Laramie SLT Full Size Pickup $11,900 Thumnail

Additional System Fields

When using multi record forms there are additional system fields available.  The are:

View_Link: The link to display this record on the single record template specified on the Query
Next_Link: The next page of results on a multi page Query
Next_Link_Lo: The sequence number of the first record on the next page
Next_Link_Hi: The sequence number of the last record on the next page
Prev_Link: The previous page of results on a multi page Query
Prev_Link_Lo: The sequence number of the first record on the previous page
Prev_Link_Hi: The sequence number of the last record on the previous page
Query_Count: The total number of records returned by a Query

These fields are useful for managing multi page forms of multiple records.  Some queries return so many records that the page produced would be very long.  Using these template fields and the search fields (MaxRecords and FirstRecord) you can easly break large queries into manageable chunks.

Advanced Multiple File, Multiple Record Templates

Sometimes when displaying a single records from one file you want to access one or more records from the same or  another data file. FlexSearch allows you to select records from another file while merging the current one by using the multi record tag with additional fields specified.  When the multi record tag is used with a file specified the fields from the specified file are available instead of the original file. 

   <!-- FlexSearch Multi-Record-Start cars.dat.Year -->
   <!-- FlexSearch Multi-Record-Start cars.dat.Make, Key, Nissan -->
   <!-- FlexSearch Multi-Record-Start cars.dat.Year, Key, 1995, 1996 -->

The first tag specifies that all records from the "cars.dat.Year" index should be output at this point in the template.  The second specifies that all records from  the "cars.dat.Make" index that match 'Nissan' should be output at this point in the template.  Finally the third specifies that all records from  the "cars.dat.Year" index that are greater than 1995 and less that 1996 should be output at this point in the template.

Related Records

Because the original file's fields are available until the sub query is in effect, values for the tag can be specified using the fields from the original file:

   <!-- FlexSearch Multi-Record-Start siblings.dat, ID, #ID# -->
   <!-- FlexSearch Multi-Record-Start person.dat, #ParType#ID, #ID# -->

The fields are replaced and then the sub query is processed. This allows access to related data files.

Top