Chapter 10. Advanced Features

Table of Contents
Nested Templates
Record manipulation using TCL
Sorting

Nested Templates

In ZAP it is possible to, from one ZAP template, call another ZAP template and display the result in the first template. This can be an advantage in some circumstances where a search is required that is impossible with a standard ZAP template.

This is done with the TCL function callZap. The function takes two argument; first the path to the ZAP template to call and second the variables to send to the ZAP template being called. The variables should be formatted the way parameters are formatted in a URL ie. name=value and separated with "&". A "?" in the beginning of the variable string is however not necessary.

All the output from the ZAP template being called will then be displayed where the callZap function is being called.

Example 10-1. Calling Templates

Let's say that we search in a database and for each record we get back we also want to check if a record with the same record id exists in another database. The search in the other database is done with the ZAP template check-id.zap and the only parameters that is send to the template is the Id number to search for, the type of search to perform and the database to search in. If we say that the records type is GRS-1 and the tag for the record id is a string tag called record-id it would look something like this in ZAP:


      (3,record-id) "Record Id: $data %{callZap check-id.zap field1=id&entry1=$data&target=$target%}"
     
The ZAP template check-id.zap would look something like this:

      %%def
      map(id)=@attr 1=1032
      syntax=grs1
      
      %%server-error init
      $name: Connection rejected 
      
      %%server-error
      Search error in $name.
      $errorstring${addinfo?\: $addinfo} ($errorcode)<br>
      
      %%server-hits 0
      This record does not exist in $target.
      
      %%server-hits 1
      This record does exist in $target.
      
      %%server-hits
      This record does exist in $target $hits times.
     
If callZap is being called in a variable declaration, only one special variable is passed from the called ZAP template, namely the variable result;.

Example 10-2. Getting results from a Template

We use the same example as above. Then it would look something like this in ZAP:


      %{setz myvar [callZap check-id.zap field1=id&entry1=$data&target=$target]%}
      (3,record-id) "Record Id: $data $myvar"
     
The ZAP template check-id.zap would look something like this:

      %%def
      map(id)=@attr 1=1032 
      syntax=grs1
      
      %%server-error init
      set result "$name: Connection rejected"
      
      %%server-error
      set result "Search error in $name.
      $errorstring${addinfo?\: $addinfo} ($errorcode)<br>"
      
      %%server-hits 0
      set result "This record does not exist in $target."
      
      %%server-hits 1
      set result "This record does exist in $target."
      
      %%server-hits
      set result "This record does exist in $target $hits times."