Template Files

Purpose: Templates are used to define the look of an interface and to guide the presentation of results, either a query or a map, to the user. A template can be either a URL (eg. http://www.somewhere.com/[ATTRIBUTE]/info.html) or HTML file(s). Simple pan/zoom interfaces use a single template file while compilicated queries often require many templates. URL templates can only be used with simple QUERY or ITEMQUERY results so many substitutions defined below are not available.

Notes: Template substitution strings are case sensitive. Attribute item substitutions must be the same case as the item names in the dbase file. ArcView and ArcInfo generally produce dbase files with item names that are all uppercase. Appropriate URL encoding (i.e. ' ' to '+') is applied when templates are URLs.

Format: Templates are simply HTML files or URL strings that contains special characters that are replaced by mapserv each time the template is processed. The simple substitution allows information such as active layers or the spatial extent to be passed from the user to mapserv and back again. Most often the new values are dumped into form variables that will be passed on again. The list of special characters and form variables is given below. HTML templates can include just about anything including javascript and java calls.

  • [get_layers]: All active layers formated for inclusion in a URL. (i.e. layer=layer1&layer=layer2 and so on...)
  • [layers]: All active layers space delimited.
  • [layername_check|select]: Used for making layers persistant across a map creation session. String is replaced with the keyword "checked", "selected" or "" if layername is on. Layername is the name of a layer as it appears in the map file.
  • [layername_desc]: Used for accessing the layer DESCRIPTION for active layers and NOT default layers. Replaced with an empty string if the layer is OFF.
  • [layername_leg]: Used for accessing the layer LEGEND for active layers and NOT default layers. Replaced with an empty string if the layer is OFF.
  • [mapx]: X coordinate of mouse click.
  • [mapy]: Y coordinate of mouse click.
  • [mapext]: Full mapextent (seperated by spaces).
  • [minx]: Minimum X coordinate of new map extent.
  • [miny]: Minimum Y coordinate of new map extent.
  • [maxx]: Maximum X coordinate of new map extent.
  • [maxy]: Maximum Y coordinate of new map extent.
  • [rawext]: Raw mapextent, that is the extent before fitting to a window size (seperated by spaces). In cases where input came from imgbox (via Java or whatever) rawext refers to imgbox coordinates transformed to map units.
  • [rawminx]: Minimum X coordinate of aww map/search extent.
  • [rawminy]: Minimum Y coordinate of raw map/search extent.
  • [rawmaxx]: Maximum X coordinate of raw map/search extent.
  • [rawmaxy]: Maximum Y coordinate of raw map/search extent.
  • [mapsize]: Current image size in cols and rows (seperated by spaces).
  • [mapwidth]: Current image width.
  • [mapheight]: Current image width.
  • [center]: Computed image center in pixels. Useful for setting imgxy form variable when map sizes change.
  • [center_x]: Computed image center x coordinate in pixels.
  • [center_y]: Computed image center y coordinate in pixels.
  • [img]: Path (relative to document root) of new image, just the image name if IMAGE_URL is not set in the mapfile
  • [ref]: Path (relative to document root) of new reference image.
  • [legend]: Path (relative to document root) of new legend image.
  • [scalebar]: Path (relative to document root) of new scalebar image.
  • [scale]: Current image scale.
  • [host]: Hostname of the web server.
  • [port]: Port the web server is listening to.
  • [pid]: Process ID.
  • [time]: Time() at the begining of the MapServer execution. Used with the process ID to build unique file names.
  • [zoom_minzoom to maxzoom_check|select]: Used for making the zoom factor persistant. Zoom values can range from -25 to 25 by default. The string is replaced with the HTML keyword "checked", "selected" or "" depending on the current zoom value.
  • [zoomdir_-1|0|1_check|select]: Used for making the zoom direction persistant. Use check with a radio control or select with a selection list. See the demo for an example. The string is replaced with the HTML keyword "checked", "selected" or "" depending on the current value of zoomdir.
  • [post or get variable name]: The contents of any variables passed to the MapServer, whether they were used or not, can be echoed this way. One use might be to have the user set a map title or north arrow style in an interactive map composer. The system doesn't care about the values, but they might be real important in creating the final output.
  • [DBASE item name]: Item name from the attribute table of a queried layer. Only attributes for the active query layers are accessible. Case must be the same as what is stored in the DBASE file. ArcView, for example, uses all caps for shapefile field names.
  • [shpext]: Extent of current shape plus a 5 percent buffer. Available only when processing query results.
  • [shpmid]: Middle of the extent of current shape. Available only when processing query results.
  • [shpminx]: Minimum X coordinate of shape extent.
  • [shpminy]: Minimum Y coordinate of shape extent.
  • [shpmaxx]: Maximum X coordinate of shape extent.
  • [shpmaxy]: Maximum Y coordinate of shape extent.
  • [zoom_minzoom to maxzoom_check|select]: Used for making the zoom factor persistant. Zoom values can range from -25 to 25 by default. The string is replaced with the HTML keyword "checked", "selected" or "" depending on the current zoom value.
  • [zoomdir_-1|0|1_check|select]: Used for making the zoom direction persistant. Use check with a radio control or select with a selection list. See the demo for an example. The string is replaced with the HTML keyword "checked", "selected" or "" depending on the current value of zoomdir.

  • For query modes that allow for multiple result sets, the following string substitutions are available. For FEATURESELECT and FEATURENSELECT modes the totals are adjusted so as not to include the selection layer. The selection layer results ARE available for display to the user.

  • [cl]: Current layer name. Useful in layer headers and footers.
  • [cld]: Current layer description. Useful in layer headers and footers.
  • [lrn]: Result number within the current layer. Starts at 1. Useful in query templates.
  • [nl]: Number of layers returning results. Useful in web header and footers.
  • [nr]: Total number of results. Useful in web header and footers.
  • [rn]: Result number within all query results. Starts at 1. Useful in web header and footers.