# Module CamlTemplate

    module CamlTemplate: sig .. end

A template processor.

Copyright © 2003, 2004, 2005 Benjamin Geer. Please see the file COPYING for licence information.

The latest version of this software can be found at http://saucecode.org/camltemplate.

# Overview

To use templates, first write template source code (see the manual for instructions). Then create a template cache using the `CamlTemplate.Cache` module, and call `CamlTemplate.Cache.get_template` to create a `CamlTemplate.template` from your template source code.

To marge a template with data, put the data in a `CamlTemplate.Model.thash`. Then call `CamlTemplate.merge`.

# Template Data Models

    module Model: sig .. end

Provides the types used in the data models that are merged with templates.

# Templates

    type template

Represents a parsed template.

    val merge : tmpl:template ->
           model:Model.thash -> buf:Buffer.t -> unit

Merges the data in a `CamlTemplate.Model.thash` with the template, and returns the resulting text in the buffer provided.
Raises `Template_error` if an error occurs in the template.

    val get_name : template -> string

Returns the name of a template.

    val dump : template -> string

Returns a simple string representation of the parse tree, for debugging purposes.

# Exceptions

    exception Syntax_error of string

Raised if an error is found when parsing template source code.

    exception Template_error of string

Raised if an error occurs when merging data with a template.

# Template Loading and Caching

    module Cache: sig .. end

Caches templates.

# Miscellaneous

    val add_web_functions : Model.thash -> unit

Adds the following template functions to a template data model:

- `urlEncode` URL-encodes a string.
- `escHtml` Escapes special characters in text to be included in an HTML document.
- `escHtmlAttr` Escapes special characters in text to be included in an HTML attribute.
- `escHtmlTextarea` Escapes special characters in text to be included in an HTML `textarea`.
- `asList` Converts any value to a list, if it isn't already a list. If the argument is a list, returns the argument. If the argument is null, returns an empty list. Otherwise, returns a single-element list containing the argument. This may be useful for dealing with form input fields that can have multiple values.

Each of these functions expects one argument.