Start of topic | Skip to actions
TWiki TemplatesDefinition of the templates used to render all HTML pages displayed in TWikiOverviewThere are three types of template:
The TWiki Template SystemTemplates are plain text with embedded template directives that tell TWiki how to compose blocks of text together to create something new.How Template Directives Work
%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. Finding TemplatesTemplates are stored either in thetwiki/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, 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 :
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 and edit respectively. The template search order is as specified above.
Master TemplatesMaster templates use the block definition directives (%TMPL:DEF and %TMPL:END% ) to define common sections that appear in two or more other templates. twiki.tmpl is the default master template.
HTML Page TemplatesHTML page templates are files of HTML mixed with template directives that tell TWiki how to build up an HTML page. As described above, the template system supports the use of 'include' directives that let you re-use the same sections of HTML - such as headers and footers - in several different places. TWiki uses HTML page templates when composing the output from all actions, like topic view, edit, and preview. This allows you to change the look and feel of all pages by editing just a few template files. HTML page templates are also used in the definition of TWikiSkins.Template TopicsTemplate topics define the default text for new topics. There are three types of template topic:When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:
Edit Template Topics and Variable ExpansionThe following variables get expanded when a user creates a new topic based on a template topic:
%STARTSECTION{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.
Template Topics in ActionHere is an example for creating new topics based on a specific template topic: The above form asks for a topic name. A hidden input tag namedtemplatetopic 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%
Automatically Generated TopicnameIf you want to make a TWiki application where you need automatically generated unique topicnames, you can use 10 X's in the edit / save URL, and they will be replaced on topic save with a count value. For example, BugIDXXXXXXXXXX will result in topics named BugID0, BugID1, BugID2 etc. Example link to create a new topic:[[%SCRIPTURLPATH{"edit"}%/%WEB%/BugIDXXXXXXXXXX?templatetopic=BugTemplate&topicparent=%TOPIC%&t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]= Master Templates by ExampleAttached is an example of an oops based templateoopsbase.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.
Base template oopsbase.tmplThe first line declares a delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing%TMPL:P{"sep"}%
Test template oopstest.tmplEach oops template basically just defines some variables and includes the base template that does the layout work.
Sample screen shot of oopstest.tmplWith URL:.../bin/oops/Sandbox/TestTopic2?template=oopstest¶m1=WebHome¶m2=WebNotify
Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory |