Embedded TCL

If you enabled TCL support when you compiled ZAP, you can embed bits of TCL code anywhere in your HTML sections. The TCL sections should begin with "%{" and end with "%}". The ZAP variables are available in the TCL interpreter, and you can generate output to the user from within the TCL script using the special command "html", which simply sends each of its arguments on to the user.

Example 7-4. Tcl embedding

TCL variables are however not directly accessible from ZAP. If you have created a variable in TCL and you want to print it out in one of your HTML sections you will have to tell ZAP explicitly that this is a TCL variable. Example:


      %{set myvar 42%}
      The value of myvar is: %{html $myvar%}
     

In order to work around the inconvenience of TCL variables not being accessible from ZAP a special set command called setz is used. Example:


      %{setz myvar 42%}
      The value of myvar is: $myvar
     

Handling targets in TCL

The list of targets is a special case. When the target list is received from an HTML form, it is done by repeating instances of the property "target" - in effect the target variable behaves as if it had several different values (corresponding to each target being searched), and there is no direct way of handling this in TCL.

To remedy this situation, the command addz has been introduced in order to make it possible to add elements to the list of targets being searched.

As an example, lets say that you, along with one or more targets you have chosen on your search page, always want to search Library of Congress. Setting target=z3950.loc.gov:7090/voyager would only overwrite the selection you have made on the search page, but the code:


      %{addz z3950.loc.gov:7090/voyager%}
     
in the %%def or %%overwrite section, would do the trick.

Environment Variables

Only a few of the web servers environment variables are available in ZAP and only as a TCL array called env. The environment variables available are QUERY_STRING, REMOTE_USER and REMOTE_IP.

In order to get the users user name in a page that is password protected you would write something like this:


      %{setz username $env(REMOTE_USER)%}
      The username is: $username