Changeset 484 for trunk/core/data/TWiki/PresentationTemplates.txt
- Timestamp:
- 11/09/08 15:46:31 (4 years ago)
- File:
-
- 1 moved
-
trunk/core/data/TWiki/PresentationTemplates.txt (moved) (moved from trunk/core/data/TWiki/TWikiTemplates.txt) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/data/TWiki/PresentationTemplates.txt
r14 r484 1 %META:TOPICINFO{author=" TWikiContributor" date="1210999363" format="1.1" version="$Rev: 16186$"}%1 %META:TOPICINFO{author="ProjectContributor" date="1111931141" format="1.0" version="$Rev: 15508 $"}% 2 2 %STARTINCLUDE% 3 ---+ TWikiTemplates3 ---+ Presentation Templates 4 4 5 _Definition of the templates used to render all HTML pages displayed in TWiki_5 _Definition of the templates used to render output_ 6 6 7 7 %TOC% … … 9 9 ---++ Overview 10 10 11 _Templates_ are plain text with embedded _template directives_ that tell TWiki how to compose blocks of text together, to create something new. 12 13 There are two types of template: 14 * *Master Templates*: Define the HTML used to display TWiki pages. 15 * *Template Topics*: Define default text when you create a new topic 16 17 __%T% Tip:__ TWiki:TWiki.TWikiTemplatesSupplement on TWiki.org has supplemental documentation on TWiki templates. 11 _Presentation Templates_ are plain text with embedded _template macros_ that describe 12 how to compose blocks of text together, to create something new. 18 13 19 14 #HtmlTemplates 20 ---++ Master Templates 21 TWiki uses master templates when composing the output from all actions, like topic view, edit, and preview. 15 Presentation templates are used composing the output from all actions, like view, edit, and preview. 22 16 This allows you to change the look and feel of all pages by editing just a few template files. 23 17 24 Master templates are also used in the definition of TWikiSkins.18 Presentation templates are also used in the definition of [[Skins]]. 25 19 26 Master templates are stored as text files with the extension =.tmpl=. 27 They are usually HTML with embedded _template directives_. 28 The directives are expanded when TWiki wants to generate a user interface screen. 20 Presentation templates are usually stored as text files with the extension 21 =.tmpl=, though can also come from topic text in some limited circumstances. 22 They are usually HTML with embedded _template macros_. 23 The macros are expanded when we wants to generate output, 24 such as a user interface screen. 29 25 30 #Template Variables26 #TemplateMacros 31 27 ---+++ How Template Directives Work 32 28 * Directives are of the form ==%<nop>TMPL:<key>%== and ==%<nop>TMPL:<key>{"attr"}%==. … … 38 34 * ==%<nop>{...}%==: is a comment. 39 35 * Two-pass processing lets you use a variable before or after declaring it. 40 * Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads only the =twiki.tmpl= mastertemplate, like =twiki.print.tmpl=, that redefines the header and footer.41 * %H% Use of template directives is optional: templates work without them.42 * %X% *NOTE:* Template directives work only for templates: they do not get processed in normal topic text.36 * PresentationTemplates and [[Skins]] work transparently and interchangeably. For example, you can create a skin that overloads only the =twiki.tmpl= master presentation template, like =twiki.print.tmpl=, that redefines the header and footer. 37 * %H% Use of template macros is optional: templates work without them. 38 * %X% *NOTE:* Most template macros work only for templates: they do not get processed in normal topic text. The one exception is =%TMPL:P=. 43 39 44 40 TMPL:P also supports simple parameters. For example, given the definition … … 48 44 49 45 Any alphanumeric characters can be used in parameter names. 50 You are highly recommended to use parameter names that cannot be confused with TWikiVariables.46 You are highly recommended to use parameter names that cannot be confused with [[Macros]]. 51 47 52 48 Note that three parameter names, =context=, =then= and =else= are *reserved*. 53 They are used to support a limited form of "if" condition that you can use to select which of two templates to use, based on a _context identifier_:49 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_: 54 50 <verbatim> 55 51 %TMPL:DEF{"link_inactive"}%<input type="button" disabled value="Link>%TMPL:END% … … 57 53 %TMPL:P{context="inactive" then="inactive_link" else="active_link"}% for %CONTEXT% 58 54 </verbatim> 59 When the "inactive" context is set, then this will expand the "link_inactive" template; otherwise it will expand the "link_active" template.55 When the "inactive" context is set, then this will expand the "link_inactive" TMPL:DEF; otherwise it will expand the "link_active" TMPL:DEF. 60 56 See IfStatements for details of supported context identifiers. 61 57 62 ---+++ Finding Templates58 ---+++ Finding Presentation Templates 63 59 64 The master templates shipped with a twikirelease are stored in the twiki/templates directory.65 As an example, ==twiki/templates/view.tmpl== is the default template file for the ==twiki/bin/view== script.60 The presentation templates shipped with a release are stored in the twiki/templates directory. 61 As an example, ==twiki/templates/view.tmpl== is the default presentation template file for the ==twiki/bin/view== script. 66 62 67 63 You can save templates in other directories as long as they are listed in the ={TemplatePath}= configuration setting. 68 64 The ={TemplatePath}= is defined in the Miscellaneous section of the [[%SCRIPTURLPATH{configure}%][configure]] page. 69 65 70 You can also save templates in user topics (_IF_ there is no possible template match in the =templates= directory).66 You can also save presentation templates in user topics (_IF_ there is no possible template match in the =templates= directory). 71 67 The ={TemplatePath}= configuration setting defines which topics will be accepted as templates. 72 68 73 Templates that are included with an explicit ='.tmpl'= extension are looked for only in the =templates/= directory.69 Presentation Templates that are included with an explicit ='.tmpl'= extension are looked for only in the =templates/= directory. 74 70 For instance =%TMPL:INCLUDE{"example.tmpl"}%= will only return =templates/example.tmpl=, regardless of ={TemplatePath}= and SKIN settings. 75 71 76 72 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. 77 The _skin path_ is set as described in TWikiSkins.73 The _skin path_ is set as described in [[Skins]]. 78 74 79 75 1 templates/%RED%web%ENDCOLOR%/%RED%script%ENDCOLOR%.%RED%skin%ENDCOLOR%.tmpl for each %RED%skin%ENDCOLOR% on the skin path 80 * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in TWikitopics instead.76 * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in topics instead. 81 77 1 templates/%RED%script%ENDCOLOR%.%RED%skin%ENDCOLOR%.tmpl for each %RED%skin%ENDCOLOR% on the skin path 82 78 1 templates/%RED%web%ENDCOLOR%/%RED%script%ENDCOLOR%.tmpl 83 * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in TWikitopics instead.79 * %X% this usage is supported *for compatibility only* and is *deprecated*. Store web-specific templates in topics instead. 84 80 1 templates/%RED%script%ENDCOLOR%.tmpl 85 1 The TWikitopic aweb.atopic if the template name can be parsed into aweb.atopic86 1 The TWikitopic %RED%web%ENDCOLOR%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path87 1 The TWikitopic %RED%web%ENDCOLOR%.%RED%Script%ENDCOLOR%Template88 1 The TWikitopic %<nop>SYSTEMWEB%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path89 1 The TWikitopic %<nop>SYSTEMWEB%.%RED%Script%ENDCOLOR%Template81 1 The topic aweb.atopic if the template name can be parsed into aweb.atopic 82 1 The topic %RED%web%ENDCOLOR%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path 83 1 The topic %RED%web%ENDCOLOR%.%RED%Script%ENDCOLOR%Template 84 1 The topic %<nop>SYSTEMWEB%.%RED%Skin%ENDCOLOR%Skin%RED%Script%ENDCOLOR%Template for each %RED%skin%ENDCOLOR% on the skin path 85 1 The topic %<nop>SYSTEMWEB%.%RED%Script%ENDCOLOR%Template 90 86 *Legend:* 91 87 * %RED%script%ENDCOLOR% refers to the script name, e.g =view=, =edit= … … 110 106 I. =%SYSTEMWEB%.ExampleTemplate= 111 107 112 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 preference variables can be used to override the templates used:108 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 preference variables can be used to override the presentation templates used: 113 109 * =VIEW_TEMPLATE= sets the template to be used for viewing a topic 114 110 * =EDIT_TEMPLATE= sets the template for editing a topic. 115 If these preferences are set locally (using _Local_ instead of _Set_) for a topic, in WebPreferences, in [[%LOCALSITEPREFS%]], or [[%SYSTEMWEB%. TWikiPreferences]] (using _Set_), the indicated templates will be chosen for =view= and =edit= respectively. The template search order is as specified above.111 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. 116 112 117 113 ---+++ TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features … … 138 134 | =%<nop>TMPL:DEF{"standardfooter"}%= | Footer, excluding revision and copyright parts | 139 135 140 #TemplateTopics 141 ---++ Template Topics 142 143 The second type of template in TWiki are template topics. Template topics define the default text for new topics. There are four types of template topic: 144 145 | *Topic Name:* | *What it is:* | 146 | WebTopicViewTemplate | Alert page shown when you try to view a nonexistent topic. This page is usually used as a prompt to help you create a new topic. | 147 | WebTopicNonWikiTemplate | Alert page shown when you try to view a nonexistent topic with a non-WikiName. Again, this page is used as a prompt to help you create the new topic. | 148 | WebTopicEditTemplate | Default text used in a new topic. | 149 | <MyCustomNamed>Template | Whenever you create a topic ending in the word "Template", it is automatically added to the list of available templates in the "Use Template" drop down field on the !WebCreateNewTopic page. | 150 151 When you create a new topic using the =edit= script, TWiki locates a topic to use as a content template according to the following search order: 152 1 A topic name specified by the =templatetopic= CGI parameter 153 * if no web is specified, the current web is searched first and then the %SYSTEMWEB% web 154 1 <nop>WebTopicEditTemplate in the current web 155 1 <nop>WebTopicEditTemplate in the %SYSTEMWEB% web 156 157 #TemplateTopicsVars 158 ---+++ Variable Expansion 159 160 When the following variables are used in a template topic, they automatically get expanded when new topic is created based on it: 161 162 | *Variable:* | *Description:* | 163 | =%<nop>DATE%= | Signature format date. See VarDATE | 164 | =%<nop>GMTIME%= | Date/time. See VarGMTIME | 165 | =%<nop>GMTIME{...}%= | Formatted date/time. See VarGMTIME2 | 166 | =%<nop>NOP%= | A no-operation variable that gets removed. Useful to prevent a SEARCH from hitting an edit template topic; also useful to escape a variable, such as =%<nop>URLPA%<nop>NOP%RAM{...}%= escaping URLPARAM | 167 | =%<nop>STARTSECTION{type="templateonly"}%%BR%...%BR%%<nop>ENDSECTION{type="templateonly"}%= | Text that gets removed when a new topic based on the template is created. See notes below. | 168 | =%<nop>SERVERTIME%= | Date/time. See VarSERVERTIME | 169 | =%<nop>SERVERTIME{...}%= | Formatted date/time. See VarSERVERTIME2 | 170 | =%<nop>USERNAME%= | Login name of user who is instantiating the new topic, e.g. %USERNAME% | 171 | =%<nop>URLPARAM{"name"}%= | Value of a named URL parameter | 172 | =%<nop>WIKINAME%= | WikiName of user who is instantiating the new topic, e.g. <nop>%WIKINAME% | 173 | =%<nop>WIKIUSERNAME%= | User name of user who is instantiating the new tpoic, e.g. <nop>%WIKIUSERNAME% | 174 175 =%<nop>STARTSECTION{type="templateonly"}%%BR%...%BR%%<nop>ENDSECTION{type="templateonly"}%= markers are used to embed text that you _do not_ want expanded when a new topic based on the template topic is created. For example, you might want to write in the template topic: 176 <pre> 177 %<nop>STARTSECTION{type="templateonly"}% 178 This template can only be changed by: 179 * Set <nop>ALLOWTOPICCHANGE = <nop>%USERSWEB%.TWikiAdminGroup 180 %<nop>ENDSECTION{type="templateonly"}% 181 </pre> 182 This will restrict who can edit the template topic, but will get removed when a new topic based on that template topic is created. 183 184 =%<nop>NOP%= can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation e.g.i escape =%<nop>SERVERTIME%= with =%<nop>SER%<nop>NOP%VERTIME%=. 185 186 All other variables are unchanged, e.g. are carried over "as is" into the new topic. 187 188 ---+++ Specifying a Form 189 When you create a new topic based on a template, you often want the new topic to have a form attached to it. You can attach a form to the template topic, in which case it will be copied into the new topic. 190 191 Sometimes this isn't quite what you want, as it copies all the existing data from the template topic into the new topic. To avoid this and use the default values specified in the form definition instead, you can use the =formtemplate= CGI parameter to the =edit= script to specify the name of a form to attach. 192 193 See TWikiScripts for information about all the other parameters to =edit=. 194 195 #AutomaticallyGeneratedTopicname 196 ---+++ Automatically Generated Topic Names 197 198 For TWiki applications it is useful to be able to automatically generate unique topicnames, such as !BugID0001, !BugID0002, etc. You can add =AUTOINC<n>= to the topic name in the edit and save scripts, and it will be replaced with an auto-incremented number on topic save. =<n>= is a number starting from 0, and may include leading zeros. Leading zeros are used to zero-pad numbers so that auto-incremented topic names can sort properly. Deleted topics are not re-used to ensure uniqueness of topic names. That is, the auto-incremented number is always higher than the existing ones, even if there are gaps in the number sequence. 199 200 *Examples:* 201 * =BugAUTOINC0= - creates topic names =Bug0=, =Bug1=, =Bug2=, ... (does not sort properly) 202 * =ItemAUTOINC0000= - creates topic names =Item0000=, =Item0001=, =Item0002=, ... (sorts properly up to 9999) 203 * =DocIDAUTOINC10001= - start with =DocID10001=, =DocID10002=, ... (sorts properly up to 99999; auto-links) 204 205 Example link to create a new topic:%BR% 206 <verbatim> 207 [[%SCRIPTURLPATH{edit}%/%WEB%/BugIDAUTOINC00001?templatetopic=BugTemplate;topicparent=%TOPIC%;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]] 208 </verbatim> 209 210 ---+++ Template Topics in Action 211 212 Here is an example for creating new topics (in the Sandbox web) based on a specific template topic and form: 213 214 <form name="new" action="%SCRIPTURLPATH{edit}%/Sandbox/"> 215 * New example topic: 216 <input type="text" name="topic" value="ExampleTopicAUTOINC0001" size="30" /> <input type="submit" class="twikiSubmit" value="Create" /> 217 <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> 218 <input type="hidden" name="topicparent" value="%TOPIC%" /> 219 <input type="hidden" name="onlywikiname" value="on" /> 220 <input type="hidden" name="onlynewtopic" value="on" /> 221 </form> 222 223 The above form asks for a topic name. A hidden input tag named ==templatetopic== specifies ExampleTopicTemplate as the template topic to use. Here is the HTML source of the form: 224 225 <pre> 226 <form name="new" action="%<nop>SCRIPTURLPATH{edit}%/Sandbox/"> 227 * New example topic: 228 <input type="text" name="topic" value="ExampleTopicAUTOINC0001" size="30" /> 229 <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> 230 <input type="hidden" name="topicparent" value="%<nop>TOPIC%" /> 231 <input type="hidden" name="onlywikiname" value="on" /> 232 <input type="hidden" name="onlynewtopic" value="on" /> 233 <input type="submit" class="twikiSubmit" value="Create" /> 234 </form> 235 </pre> 236 237 See TWikiScripts#edit for details of the parameters that the =edit= script understands. 238 239 %T% *TIP:* You can use the =%<nop>WIKIUSERNAME%= and =%<nop>DATE%= variables in your topic templates to include the signature of the person creating a new topic. The variables are expanded into fixed text when a new topic is created. The standard signature is: <br /> 240 ==-- %<nop>WIKIUSERNAME% - %<nop>DATE%== 241 242 ---+++ Using Absolute vs Relative URLs in Templates 243 244 When you use TWikiVariables such as %<nop>PUBURL% and %<nop>PUBURLPATH% in templates you should be aware that using %<nop>PUBURL% instead of %<nop>PUBURLPATH% puts absolute URLs in the produced HTML. This means that when a user saves a TWiki page in HTML and emails the file to someone outside a company firewall, the receiver has a severe problem viewing it. It is therefore recommended always to use the %<nop>PUBURLPATH% to refer to images, CSS, Javascript files etc so links become relative. This way browsers just give up right away and show a usable html file. 245 246 __Related Topics:__ TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory 136 __Related Topics:__ [[Skins]] 247 137 248 138 %STOPINCLUDE% 249 -- __Contributors:__ TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie
Note: See TracChangeset
for help on using the changeset viewer.
