wiki:Doc/panc/advanced

Advanced Topics

Modifying the Template Load Path

The pan compiler uses a load path defined on the command line to autoload templates. The autoload procedure stops with the first existing template and will load a template of a given name only once. One can use the LOADPATH variable to add additional relative paths to the search path during the evaluation of an object template. This variable must be a list of relative paths given as strings. This functionality can be used for example (in conjunction with namespaces) to switch between production and test versions of templates easily:

object template test; 
variable LOADPATH = ’production’; 
#variable LOADPATH = ’test’; 
include ’service_configuration’; 
... 

With a path given on the command line like /pan, the pan compiler will search in /pan and then /pan/production for the template named service configuration. Uncommenting the test line and commenting the production line will search /pan/test rather than /pan/production.

All combinations of the paths given on the command line and those given in the LOADPATH variable are searched until the needed template is found. The first path from the command line is searched first, followed by all combinations of that path with those in the LOADPATH variable (in order), then the second path from the command line, and so on.

Using Namespaces

The pan compiler allows templates to be organized into a hierarchical directory structure. Template names may contain the slash character which acts as a directory separator. For example, one can define a structure template:

structure template test/stemplate; 
’alpha’ = 20; 

which can be included by the following object template:

object template test;
include 'test/stemplate';

assuming that the location in the file system is rootdir/test/stemplate.tpl and rootdir is include in the compiler's load path.

Note that the full template name must always be used in the include statement and the template must always be a relative name (i.e. does not begin with a slash). Object templates may not have a namespaced name.

Last modified 17 years ago Last modified on Mar 4, 2007, 10:51:54 PM