| 1 | = Advanced Topics = |
| 2 | [[TracNav]] |
| 3 | |
| 4 | == Modifying the Template Load Path == |
| 5 | |
| 6 | The pan compiler uses a load path defined on the command line to autoload templates. The autoload |
| 7 | procedure stops with the first existing template and will load a template of a given name only once. |
| 8 | One can use the LOADPATH variable to add additional relative paths to the search path. It must |
| 9 | be a list of relative paths as strings. This functionality can be used for example (in conjunction with |
| 10 | namespaces) to switch between production and test versions of templates easily: |
| 11 | object template test; |
| 12 | variable LOADPATH = ’production’; |
| 13 | #variable LOADPATH = ’test’; |
| 14 | include ’service_configuration’; |
| 15 | ... |
| 16 | With a path given on the command line like {{{/pan}}}, the pan compiler will search in {{{/pan}}} and then |
| 17 | {{{/pan/production}}} for the template named service configuration. Uncommenting the test |
| 18 | line and commenting the production line will search {{{/pan/test}}} rather than {{{/pan/production}}}. |
| 19 | All combinations of the paths given on the command line and those given in the LOADPATH variable |
| 20 | are searched until the needed template is found. The first path from the command line is searched first, |
| 21 | followed by all combinations of that path with those in the LOADPATH variable (in order), then the |
| 22 | second path from the command line, and so on. |
| 23 | |
| 24 | == Using Namespaces == |
| 25 | |
| 26 | The pan compiler allows templates to be organized into a hierarchical directory structure. Template |
| 27 | names may contain the slash character which acts as a directory separator. For example, one can define |
| 28 | a structure template: |
| 29 | {{{ |
| 30 | structure template test/stemplate; |
| 31 | ’alpha’ = 20; |
| 32 | }}} |
| 33 | which can be included by the following object template: |
| 34 | {{{ |
| 35 | object template test; |
| 36 | include 'test/stemplate'; |
| 37 | }}} |
| 38 | assuming that the location in the file system is {{{rootdir/test/stemplate.tpl}}} and {{{rootdir}}} is include in the compiler's load path. |
| 39 | |
| 40 | 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. |