1 Introduction
This manual describes how to use CamlTemplate, a template processor for
Objective Caml programs. It can be used to generate web pages,
scripts, SQL queries, XML documents and other sorts of text.
1.1 About This Manual
This manual is provided in HTML and PDF formats in the CamlTemplate
distribution.
1.2 Licence
CamlTemplate is free software, released under the
GNU General Public License. This manual is released under the same
licence.
In addition, as a special exception, Benjamin Geer gives permission to link the code of
this program with the Apache HTTP Server (or with modified versions of Apache that use the
same license as Apache), and distribute linked combinations including the two. You must
obey the GNU General Public License in all respects for all of the code used other than
Apache. If you modify this file, you may extend this exception to your version of the
file, but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
1.3 Features
-
A versatile, easy-to-learn template syntax that supports common scripting-language
constructs, while encouraging a separation between presentation logic and application
logic.
- The supported Caml data structures accomodate lists, tables and trees of items in a
straightforward manner.
- Works well with mod_caml.
- Supports any ASCII-compatible encoding, including UTF-8.
- Optional support for multithreading.
CamlTemplate works by merging data with handwritten templates. This process is
illustrated in Figure 1.
The template contains only the handwritten material; some other program provides the data.
The template's author doesn't need to be involved in writing that program; he or she only
needs to know what data the program provides, and can therefore change the template
without involving the program's developers. Likewise, the program can be modified so that
it obtains data in a different way, without affecting the template. Different templates
can be used to display the same data in different ways (e.g. to generate normal and
`printer-friendly' versions of a web page).
Figure 1: Generating a document
1.4 Getting CamlTemplate
The CamlTemplate source code and documentation can be downloaded from the
CamlTemplate web site.
1.5 Installing CamlTemplate
1.5.1 Installing with GODI
If you use GODI, you can install CamlTemplate from godi_console.
Otherwise, you can install manually as described below.
1.5.2 Installing Manually
Requirements:
Unpack the archive:
tar zxf camltemplate-x.y.z.tar.gz
cd camltemplate-x.y.z
To see the configuration options, type:
./configure --help
If you need thread support, type:
./configure --enable-threads
(Note that thread support doesn't currently work with mod_caml.) If you don't need
thread support and want to install in the default locations, type:
./configure
Then type:
make
make opt
make test
If there are no errors, type make install as root. This installs the byte-code and
native-code versions of the camltemplate library. Documentation is installed in
$PREFIX/doc/camltemplate. Example programs are installed in $PREFIX/share/camltemplate.
To uninstall the library, type make uninstall as root.
1.5.3 Installing with mod_caml
You'll need mod_caml 1.0.6 or above and Apache 1.3. (Apache 2.0
seems to be incompatible with modules that use recent versions
of PCRE.)
First, install CamlTemplate as described in Section 1.5.2, without
thread support.
Then compile and install mod_caml. Make sure it works correctly on its own (try the hello.ml example that comes with it) before proceeding.
If you're using Objective Caml 3.07, you're done; you can now try try compiling and
installing the example in examples/mod_caml.
If you're running Objective Caml 3.06, find this line in your httpd.conf:
CamlLoad /path/to/registry.cmo
After that line, add the following, and restart Apache:
CamlAddInterface Parsing
CamlAddInterface Lexing
CamlAddInterface Obj
CamlLoad /path/to/camltemplate.cma
(If you don't know where camltemplate.cma is, you can find it by typing ocamlfind query camltemplate).
Now try compiling and installing the example in examples/mod_caml.
1.6 Mailing List and Support
The camltemplate mailing list is used for questions,
suggestions, bug reports and discussion about CamlTemplate.
There is also a Frequently Asked Questions page.
1.7 Author
CamlTemplate is developed and maintained by Benjamin Geer.
1.8 History
In 1999, Benjamin Geer wrote a template processor in Java, called
FreeMarker, based on the experience of using a similar tool
with graphic designers in a web development shop. CamlTemplate borrows some aspects of
FreeMarker (small library not tied to web development, JavaScript-like expressions,
Perl-like data structures), as well as some ideas from the Apache Jakarta project's
Velocity template processor (generated parser, more concise
syntax), released in 2001. The first version of CamlTemplate was released in October
2003.