colas@0
|
1 |
---+ Package =TWiki::Templates=
|
colas@0
|
2 |
|
colas@0
|
3 |
Support for the TWiki template language.
|
colas@0
|
4 |
|
colas@0
|
5 |
|
colas@0
|
6 |
%TOC%
|
colas@0
|
7 |
|
colas@0
|
8 |
The following tokens are supported by this language:
|
colas@0
|
9 |
|
colas@0
|
10 |
| %<nop>TMPL:P% | Instantiates a previously defined template |
|
colas@0
|
11 |
| %<nop>TMPL:DEF% | Opens a template definition |
|
colas@0
|
12 |
| %<nop>TMPL:END% | Closes a template definition |
|
colas@0
|
13 |
| %<nop>TMPL:INCLUDE% | Includes another file of templates |
|
colas@0
|
14 |
|
colas@0
|
15 |
Note; the template cache does not get reset during initialisation, so
|
colas@0
|
16 |
the haveTemplate test will return true if a template was loaded during
|
colas@0
|
17 |
a previous run when used with mod_perl or speedycgi. Frustrating for
|
colas@0
|
18 |
the template author, but they just have to switch off
|
colas@0
|
19 |
the accelerators during development.
|
colas@0
|
20 |
|
colas@0
|
21 |
This is to all intents and purposes a singleton object. It could
|
colas@0
|
22 |
easily be coverted into a true singleton (template manager).
|
colas@0
|
23 |
|
colas@0
|
24 |
|
colas@0
|
25 |
---++ ClassMethod *new* <tt>($session)</tt>
|
colas@0
|
26 |
|
colas@0
|
27 |
Constructor. Creates a new template database object.
|
colas@0
|
28 |
* $session - session (TWiki) object
|
colas@0
|
29 |
|
colas@0
|
30 |
|
colas@0
|
31 |
|
colas@0
|
32 |
---++ ObjectMethod *finish* <tt>()</tt>
|
colas@0
|
33 |
Break circular references.
|
colas@0
|
34 |
|
colas@0
|
35 |
|
colas@0
|
36 |
|
colas@0
|
37 |
---++ ObjectMethod *haveTemplate* <tt>($name) -> $boolean</tt>
|
colas@0
|
38 |
|
colas@0
|
39 |
Return true if the template exists and is loaded into the cache
|
colas@0
|
40 |
|
colas@0
|
41 |
|
colas@0
|
42 |
|
colas@0
|
43 |
---++ ObjectMethod *expandTemplate* <tt>($params) -> $string</tt>
|
colas@0
|
44 |
|
colas@0
|
45 |
Expand the template specified in the parameter string using =tmplP=.
|
colas@0
|
46 |
|
colas@0
|
47 |
Examples:
|
colas@0
|
48 |
<verbatim>
|
colas@0
|
49 |
$tmpls->expandTemplate('"blah");
|
colas@0
|
50 |
$tmpls->expandTemplate('context="view" then="sigh" else="humph"');
|
colas@0
|
51 |
|
colas@0
|
52 |
|
colas@0
|
53 |
|
colas@0
|
54 |
---++ ObjectMethod *tmplP* <tt>($attrs) -> $string</tt>
|
colas@0
|
55 |
|
colas@0
|
56 |
Return value expanded text of the template, as found from looking
|
colas@0
|
57 |
in the register of template definitions. The attrs can contain a template
|
colas@0
|
58 |
name in _DEFAULT, and / or =context=, =then= and =else= values.
|
colas@0
|
59 |
|
colas@0
|
60 |
Recursively expands any contained TMPL:P tags.
|
colas@0
|
61 |
|
colas@0
|
62 |
Note that it would be trivial to add template parameters to this,
|
colas@0
|
63 |
simply by iterating over the other parameters (other than _DEFAULT, context,
|
colas@0
|
64 |
then and else) and doing a s/// in the template for that parameter value. This
|
colas@0
|
65 |
would add considerably to the power of templates. There is already code
|
colas@0
|
66 |
to do this in the MacrosPlugin.
|
colas@0
|
67 |
|
colas@0
|
68 |
|
colas@0
|
69 |
|
colas@0
|
70 |
---++ ObjectMethod *readTemplate* <tt>($name,$skins,$web) -> $text</tt>
|
colas@0
|
71 |
|
colas@0
|
72 |
Return value: expanded template text
|
colas@0
|
73 |
|
colas@0
|
74 |
Reads a template, constructing a candidate name for the template thus
|
colas@0
|
75 |
0 looks for file =$name.$skin.tmpl= (for each skin)
|
colas@0
|
76 |
0 in =templates/$web=
|
colas@0
|
77 |
0 in =templates=, look for
|
colas@0
|
78 |
0 looks for file =$name.tmpl=
|
colas@0
|
79 |
0 in =templates/$web=
|
colas@0
|
80 |
0 in =templates=, look for
|
colas@0
|
81 |
0 if a template is not found, tries in this order
|
colas@0
|
82 |
0 parse =$name= into a web name (default to $web) and a topic name and looks for this topic
|
colas@0
|
83 |
0 looks for topic =${skin}Skin${name}Template=
|
colas@0
|
84 |
0 in $web (for each skin)
|
colas@0
|
85 |
0 in =TWiki::cfg{SystemWebName}= (for each skin)
|
colas@0
|
86 |
0 looks for topic =${name}Template=
|
colas@0
|
87 |
0 in $web (for each skin)
|
colas@0
|
88 |
0 in =TWiki::cfg{SystemWebName}= (for each skin)
|
colas@0
|
89 |
In the event that the read fails (template not found, access permissions fail)
|
colas@0
|
90 |
returns the empty string ''.
|
colas@0
|
91 |
|
colas@0
|
92 |
=$skin=, =$web= and =$name= are forced to an upper-case first character
|
colas@0
|
93 |
when composing user topic names.
|
colas@0
|
94 |
|
colas@0
|
95 |
If template text is found, extracts include statements and fully expands them.
|
colas@0
|
96 |
Also extracts template definitions and adds them to the
|
colas@0
|
97 |
list of loaded templates, overwriting any previous definition.
|
colas@0
|
98 |
|
colas@0
|
99 |
|