%TMPL:<key>%
and %TMPL:<key>{"attr"}%
.
%TMPL:INCLUDE{"file"}%
: Includes a template file. The file is found as described below.
%TMPL:DEF{"block"}%
: Define a block. Text between this and the %TMPL:END%
directive is not used in-place, but is saved for later use with %TMPL:P
. Leading and trailing whitespace is ignored.
%TMPL:END%
: Ends a block definition.
%TMPL:P{"var"}%
: Includes a previously defined block.
%{...}%
: is a comment.
twiki.tmpl
master template, like twiki.print.tmpl
, that redefines the header and footer.
%TMPL:DEF{"x"}% x%P%z%TMPL:END%
then %TMPL:P{"x" P="y"}%
will expand to xyz
.
Note that parameters can simply be ignored; for example=%TMPL:P{"x"}%= will expand to x%P%z.
Any alphanumeric characters can be used in parameter names. You are highly recommended to use parameter names that cannot be confused with TWikiVariables.
Note that three parameter names, context
, then
and else
are reserved. 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:
%TMPL:DEF{"link_inactive"}%<input type="button" disabled value="Link>%TMPL:END% %TMPL:DEF{"link_active"}%<input type="button" onclick="link()" value="Link" />%TMPL:END% %TMPL:P{context="inactive" then="inactive_link" else="active_link"}% for %CONTEXT%When the "inactive" context is set, then this will expand the "link_inactive" template; otherwise it will expand the "link_active" template. See IfStatements for details of supported context identifiers.
twiki/templates
directory, or can also be read from user topics. As an example, twiki/templates/view.tmpl
is the default template file for the twiki/bin/view
script.
Templates that are included using %TMPL:INCLUDE%
are also found using the same search algorithm, unless you explicitly put '.tmpl'
at the end of the template name. In this case, the string is assumed to be the full name of a template in the templates
directory, and the algorithm isn't used.
TWiki uses the following search order to determine which template file or topic to use for a particular script. The skin path is set as described in TWikiSkins.
For example, theLegend:
- templates/web/script.skin.tmpl for each skin on the skin path
- this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
- templates/script.skin.tmpl for each skin on the skin path
- templates/web/script.tmpl
- this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
- templates/script.tmpl
- The TWiki topic web.topic if the template name can be parsed into web.topic
- The TWiki topic web.SkinSkinScriptTemplate for each skin on the skin path
- The TWiki topic web.ScriptTemplate
- The TWiki topic TWiki.SkinSkinScriptTemplate for each skin on the skin path
- The TWiki topic TWiki.ScriptTemplate
- script refers to the script name, e.g
view
,edit
- Script refers to the same, but with the first character capitalized, e.g
View
- skin 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.- Skin refers to the same, but with the first character capitalized, e.g
Dragon
- web refers to the current web
example
template file will be searched for in the following places, when the current web is Thisweb
and the skin path is print,pattern
: templates/Thisweb/example.print.tmpl
deprecated; don't rely on it
templates/Thisweb/example.pattern.tmpl
deprecated; don't rely on it
templates/example.print.tmpl
templates/example.pattern.tmpl
templates/Thisweb/example.tmpl
deprecated; don't rely on it
templates/example.tmpl
Thisweb.PrintSkinExampleTemplate
Thisweb.PatternSkinExampleTemplate
Thisweb.ExampleTemplate
TWiki.PrintSkinExampleTemplate
TWiki.PatternSkinExampleTemplate
TWiki.ExampleTemplate
view
and edit
scripts, for example when a topic-specific template is required. Two preference variables can be user to override the templates used: VIEW_TEMPLATE
sets the template to be used for viewing a topic
EDIT_TEMPLATE
sets the template for editing a topic.
view
and edit
respectively. The template search order is as specified above.
%TMPL:DEF
and %TMPL:END%
) to define common sections that appear in two or more other templates. twiki.tmpl
is the default master template.
Template variable: Defines: %TMPL:DEF{"sep"}% "|" separator %TMPL:DEF{"htmldoctype"}% Start of all HTML pages %TMPL:DEF{"standardheader"}% Standard header (ex: view, index, search) %TMPL:DEF{"simpleheader"}% Simple header with reduced links (ex: edit, attach, oops) %TMPL:DEF{"standardfooter"}% Footer, excluding revision and copyright parts %TMPL:DEF{"oops"}% Skeleton of oops dialog
When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:
Topic Name: What it is: WebTopicViewTemplate Error page shown when you try to view a nonexistent topic WebTopicNonWikiTemplate Alert page shown when you try to view a nonexistent topic with a non-WikiName WebTopicEditTemplate Default text shown when you create a new topic.
templatetopic
CGI parameter
Variable: Description: %DATE%
Signature format date. See VarDATE %GMTIME%
Date/time. See VarGMTIME %GMTIME{...}%
Formatted date/time. See VarGMTIME2 %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 like %URLPARAM%NOP%{...}%
%STARTSECTION{type="templateonly"}%
...
%ENDSECTION{type="templateonly"}%Text that gets removed when a new topic based on the template is created. See notes below. %SERVERTIME%
Date/time. See VarSERVERTIME %SERVERTIME{...}%
Formatted date/time. See VarSERVERTIME2 %USERNAME%
Login name of user who is instantiating the new topic, e.g. guest %URLPARAM{"name"}%
Value of a named URL parameter %WIKINAME%
WikiName of user who is instantiating the new topic, e.g. TWikiGuest %WIKIUSERNAME%
User name of user who is instantiating the new tpoic, e.g. Main.TWikiGuest
%STARTSECTION{type="templateonly"}%
...
%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:
%STARTSECTION{type="templateonly"}% This template can only be changed by: * Set ALLOWTOPICCHANGE = %MAINWEB%.TWikiAdminGroup %ENDSECTION{type="templateonly"}%This will restrict who can edit the template topic, but will get removed when a new topic based on that template topic is created.
%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 %SER%NOP%VERTIME%
.
All other variables are unchanged, e.g. are carried over "as is" into the new topic.
templatetopic
specifies ExampleTopicTemplate as the template topic to use. Here is the HTML source of the form:
<form name="new" action="%SCRIPTURLPATH{edit}%/%WEB%/"> * New example topic: <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="26" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> <input type="hidden" name="topicparent" value="%TOPIC%" /> <input type="hidden" name="onlywikiname" value="on" /> <input type="hidden" name="onlynewtopic" value="on" /> <input type="submit" class="twikiSubmit" value="Create" /> (date format is <nop>YYYYxMMxDD) </form>See TWikiScripts for details of the parameters that the
edit
script understands.
TIP: You can use the %WIKIUSERNAME%
and %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: -- %WIKIUSERNAME% - %DATE%
[[%SCRIPTURLPATH{"edit"}%/%WEB%/BugIDXXXXXXXXXX?templatetopic=BugTemplate&topicparent=%TOPIC%&t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]=
oopsbase.tmpl
and an example oops dialog oopstest.tmpl
based on the base template. NOTE: This isn't the release version, just a quick, simple demo.
%TMPL:P{"sep"}%
%TMPL:DEF{"sep"}% | %TMPL:END% <html> <head> <title> %WIKITOOLNAME% . %WEB% . %TOPIC% %.TMPL:P{"titleaction"}%</title> <base href="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%"> <meta name="robots" content="noindex"> </head> <body bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="3" cellspacing="0"> <tr> <td bgcolor="%WEBBGCOLOR%" rowspan="2" valign="top" width="1%"> <a href="%WIKIHOMEURL%"> <img src="%PUBURLPATH%/wikiHome.gif" border="0"></a> </td> <td> <b>%WIKITOOLNAME% . %WEB% . </b><font size="+2"> <B>%TOPIC%</b> %TMPL:P{"titleaction"}%</font> </td> </tr> <tr bgcolor="%WEBBGCOLOR%"> <td colspan="2"> %TMPL:P{"webaction"}% </td> </tr> </table> --- ++ %TMPL:P{"heading"}% %TMPL:P{"message"}% <table width="100%" border="0" cellpadding="3" cellspacing="0"> <tr bgcolor="%WEBBGCOLOR%"> <td valign="top"> Topic <b>%TOPIC%</b> . { %TMPL:P{"topicaction"}% } </td> </tr> </table> </body>
%TMPL:DEF{"titleaction"}% (test =titleaction=) %TMPL:END% %TMPL:DEF{"webaction"}% test =webaction= %TMPL:END% %TMPL:DEF{"heading"}% Test heading %TMPL:END% %TMPL:DEF{"message"}% Test =message=. Blah blah blah blah blah blah blah blah blah blah blah... * Some more blah blah blah blah blah blah blah blah blah blah... * Param1: %PARAM1% * Param2: %PARAM2% * Param3: %PARAM3% * Param4: %PARAM4% %TMPL:END% %TMPL:DEF{"topicaction"}% Test =topicaction=: [[%WEB%.%TOPIC%][OK]] %TMPL:P{"sep"}% [[%TWIKIWEB%.TWikiRegistration][Register]] %TMPL:END% %TMPL:INCLUDE{"oopsbase"}%
.../bin/oops/Sandbox/TestTopic2?template=oopstest¶m1=WebHome¶m2=WebNotify
Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
USER REFERENCES
ADMIN MAINTENANCE
CATEGORIES WEBS PERSONAL |
Copyright © by the contributing authors. Bernstein - The Memory of Paper http://www.bernstein.oeaw.ac.at Ideas, requests, problems regarding Bernstein? Send feedback Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TWikiTemplates |