~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/data/System/SkinTemplates.txt

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%META:TOPICINFO{author="ProjectContributor" date="1231502400" format="1.1" version="1"}%
 
2
%STARTINCLUDE%
 
3
---+ Skin Templates
 
4
 
 
5
_Definition of the templates used to render output_ 
 
6
 
 
7
%TOC%
 
8
 
 
9
%STARTSECTION{"PowerUserGuide"}%
 
10
---++ Overview
 
11
 
 
12
_Skin Templates_ are plain text with embedded _template macros_ that describe how to compose blocks of text together, to create something new.
 
13
 
 
14
#HtmlTemplates
 
15
Skin templates are used composing the output from all actions, like view, edit, and preview. This allows you to change the look and feel of all pages by editing just a few template files.
 
16
 
 
17
Skin templates are usually stored as text files with the extension =.tmpl=, though can also come from topic text in some limited circumstances. They are usually HTML with embedded _template macros_. The macros are expanded when we want to generate output, such as a user interface screen.
 
18
 
 
19
#TemplateMacros
 
20
---++ How Template Directives Work
 
21
   * Directives are of the form ==%<nop>TMPL:&lt;key&gt;%== and ==%<nop>TMPL:&lt;key&gt;{"attr"}%==.
 
22
   * Directives:
 
23
      * ==%<nop>TMPL:INCLUDE{"file"}%==: Includes a template file. The file is found as described [[#FindingTemplates][below]].
 
24
      * ==%<nop>TMPL:DEF{"block"}%==: Define a block. *All* text between this and the next =%<nop>TMPL:END%= directive is removed and saved for later use with  %<nop>TMPL:P=.
 
25
      * ==%<nop>TMPL:END%==: Ends a block definition.
 
26
      * ==%<nop>TMPL:P{"var"}%==: Includes a previously defined block.
 
27
      * ==%<nop>{...}%==: is a comment.
 
28
   * Two-pass processing lets you use a defined block before or after declaring it.
 
29
   * For example, you can create a skin that overloads only the =foswiki.tmpl= master skin template, like =foswiki.print.tmpl=, that redefines the header and footer.
 
30
   * %H% Use of template macros is optional: templates work without them.
 
31
   * %X% Most template macros work only for templates: they do not get processed in normal topic text. The one exception is =%TMPL:P=.
 
32
 
 
33
TMPL:P also supports simple parameters. For example, given the definition
 
34
=%<nop>TMPL:DEF{"x"}% x%<nop>P%z%<nop>TMPL:END%= then =%<nop>TMPL:P{"x" P="y"}%= will expand to =xyz=.
 
35
 
 
36
Note that parameters can simply be ignored; for example, =%<nop>TMPL:P{"x"}%= will expand to x%<nop>P%z.
 
37
 
 
38
Any alphanumeric characters can be used in parameter names.
 
39
You are highly recommended to use parameter names that cannot be confused with [[macros]].
 
40
 
 
41
Note that three parameter names, =context=, =then= and =else= are *reserved*.
 
42
They are used to support a limited form of "if" condition that you can use to select which of two TMPL:DEFs to use, based on a _context identifier_:
 
43
<verbatim>
 
44
%TMPL:DEF{"link_inactive"}%<input type="button" disabled value="Link>%TMPL:END%
 
45
%TMPL:DEF{"link_active"}%<input type="button" onclick="link()" value="Link" />%TMPL:END%
 
46
%TMPL:P{context="inactive" then="inactive_link" else="active_link"}% for %CONTEXT%
 
47
</verbatim>
 
48
When the "inactive" context is set, then this will expand the "link_inactive" TMPL:DEF; otherwise it will expand the "link_active" TMPL:DEF.
 
49
See IfStatements for details of supported context identifiers.
 
50
 
 
51
#FindingTemplates
 
52
---++ Finding Skin Templates
 
53
 
 
54
The skin templates shipped with a release are stored in the =templates= directory.
 
55
As an example, ==templates/view.tmpl== is the default skin template file for the ==bin/view== script. 
 
56
 
 
57
You can save templates in other directories as long as they are listed in the ={TemplatePath}= configuration setting.
 
58
The ={TemplatePath}= is defined in the Miscellaneous section of the [[%SCRIPTURLPATH{configure}%][configure]] page.
 
59
 
 
60
You can also save skin templates in user topics (_IF_ there is no possible template match in the =templates= directory).
 
61
The ={TemplatePath}= configuration setting defines which topics will be accepted as templates.
 
62
 
 
63
Skin templates that are included with an explicit ='.tmpl'= extension are looked for only in the =templates/= directory.
 
64
For instance =%TMPL:INCLUDE{"example.tmpl"}%= will only return =templates/example.tmpl=, regardless of ={TemplatePath}= and SKIN settings.
 
65
 
 
66
The out-of-the-box setting of ={TemplatePath}= supports the following search order to determine which template file or topic to use for a particular script or =%TMPL:INCLUDE{"script"}%= statement.
 
67
The _skin path_ is set as described in [[Skins]].
 
68
 
 
69
   1 templates/%RED%web%ENDCOLOR%/%RED%script%ENDCOLOR%.%RED%skin%ENDCOLOR%.tmpl for each %RED%skin%ENDCOLOR% on the skin path
 
70
      * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in topics instead.
 
71
   1 templates/%RED%script%ENDCOLOR%.%RED%skin%ENDCOLOR%.tmpl for each %RED%skin%ENDCOLOR% on the skin path
 
72
   1 templates/%RED%web%ENDCOLOR%/%RED%script%ENDCOLOR%.tmpl
 
73
      * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in topics instead.
 
74
   1 templates/%RED%script%ENDCOLOR%.tmpl
 
75
   1 The topic aweb.atopic if the template name can be parsed into aweb.atopic
 
76
   1 The topic %RED%web%ENDCOLOR%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path
 
77
   1 The topic %RED%web%ENDCOLOR%.%RED%Script%ENDCOLOR%Template
 
78
   1 The topic %<nop>SYSTEMWEB%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path
 
79
   1 The topic %<nop>SYSTEMWEB%.%RED%Script%ENDCOLOR%Template
 
80
*Legend:*
 
81
   * %RED%script%ENDCOLOR% refers to the script name, e.g =view=, =edit=
 
82
   * %RED%Script%ENDCOLOR% refers to the same, but with the first character capitalized, e.g =View=
 
83
   * %RED%skin%ENDCOLOR% refers to a skin name, e.g =dragon=, =pattern=. All skins are checked at each stage, in the order they appear in the skin path.
 
84
   * %RED%Skin%ENDCOLOR% refers to the same, but with the first character capitalized, e.g =Dragon=
 
85
   * %RED%web%ENDCOLOR% refers to the current web
 
86
 
 
87
For example, the =example= template file will be searched for in the following places, when the current web is =Thisweb= and the skin path is =print,pattern=:
 
88
 
 
89
   I. =templates/Thisweb/example.print.tmpl= _deprecated; don't rely on it_
 
90
   I. =templates/Thisweb/example.pattern.tmpl= _deprecated; don't rely on it_
 
91
   I. =templates/example.print.tmpl=
 
92
   I. =templates/example.pattern.tmpl=
 
93
   I. =templates/Thisweb/example.tmpl= _deprecated; don't rely on it_
 
94
   I. =templates/example.tmpl=
 
95
   I. =Thisweb.PrintSkinExampleTemplate=
 
96
   I. =Thisweb.PatternSkinExampleTemplate=
 
97
   I. =Thisweb.ExampleTemplate=
 
98
   I. =%SYSTEMWEB%.PrintSkinExampleTemplate=
 
99
   I. =%SYSTEMWEB%.PatternSkinExampleTemplate=
 
100
   I. =%SYSTEMWEB%.ExampleTemplate=
 
101
 
 
102
Template names are usually derived from the name of the currently executing script; however it is also possible to override these settings in the =view= and =edit= scripts, for example when a topic-specific template is required. Two [[%SYSTEMWEB%.PreferenceSettings][preference settings]] can be used to override the skin templates used:
 
103
   * =VIEW_TEMPLATE= sets the template to be used for viewing a topic.
 
104
   * =EDIT_TEMPLATE= sets the template for editing a topic.
 
105
If these preferences are set locally (using _Local_ instead of _Set_) for a topic, in WebPreferences, in [[%LOCALSITEPREFS%]], or [[%SYSTEMWEB%.DefaultPreferences]] (using _Set_), the indicated templates will be chosen for =view= and =edit= respectively. The template search order is as specified above.
 
106
 
 
107
---++ TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features
 
108
 
 
109
If there is recursion in the TMPL:INCLUDE chain (eg view.tmpl contains =%<nop>TMPL:INCLUDE{"foswiki"}%=, the templating system will include the next SKIN in the skin path. 
 
110
For example, to create a customisation of pattern skin, where you _only_ want to over-ride the breadcrumbs for the view script, you can create only a view.yourlocal.tmpl:
 
111
<verbatim>
 
112
%TMPL:INCLUDE{"view"}%
 
113
%TMPL:DEF{"breadcrumb"}% We don't want any crumbs %TMPL:END%
 
114
</verbatim>
 
115
and then set SKIN=yourlocal,pattern
 
116
 
 
117
The default ={TemplatePath}= will not give you the desired result if you put these statements in the topic =Thisweb.YourlocalSkinViewTemplate=. The default ={TemplatePath}= will resolve the request to the =template/view.pattern.tmpl=, before it gets to the =Thisweb.YourlocalSkinViewTemplate= resolution. You can make it work by prefixing the ={TemplatePath}= with: =$web.YourlocalSkin$nameTemplate=. 
 
118
 
 
119
---++ Default master template
 
120
 
 
121
==foswiki.tmpl== is the default master template. It defines the following sections.
 
122
 
 
123
| *Template directive:* | *Defines:* |
 
124
| =%<nop>TMPL:DEF{"sep"}%= | "&#124;" separator |
 
125
| =%<nop>TMPL:DEF{"htmldoctype"}%= | Start of all HTML pages |
 
126
| =%<nop>TMPL:DEF{"standardheader"}%= | Standard header (ex: view, index, search)  |
 
127
| =%<nop>TMPL:DEF{"simpleheader"}%= | Simple header with reduced links (ex: edit, attach, oops) |
 
128
| =%<nop>TMPL:DEF{"standardfooter"}%= | Footer, excluding revision and copyright parts |
 
129
 
 
130
%ENDSECTION{"PowerUserGuide"}%
 
131
 
 
132
---
 
133
*Related Topics:* [[Skins]]
 
134
 
 
135
%STOPINCLUDE%