|
TWiki Templates |
| All three types of template use the TWiki template system. |
|
> > | Tip: TWiki:TWiki.TWikiTemplatesSupplement on TWiki.org has supplemental documentation on TWiki templates. |
| The TWiki Template System
Templates are plain text with embedded template directives that tell TWiki how to compose blocks of text together to create something new. |
|
- Directives are of the form
%TMPL:<key>% and %TMPL:<key>{"attr"}% .
- Directives:
-
%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:DEF{"block"}% : Define a block. All text between this and the next %TMPL:END% directive is removed and saved for later use with %TMPL:P .
|
|
-
-
%TMPL:END% : Ends a block definition.
-
%TMPL:P{"var"}% : Includes a previously defined block.
-
%{...}% : is a comment.
|
|
- 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 aweb.atopic if the template name can be parsed into aweb.atopic
|
|
- 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
|
> > |
- The TWiki topic %TWIKIWEB%.SkinSkinScriptTemplate for each skin on the skin path
- The TWiki topic %TWIKIWEB%.ScriptTemplate
|
| Legend:
- script refers to the script name, e.g
view , edit
- Script refers to the same, but with the first character capitalized, e.g
View
|
|
-
EDIT_TEMPLATE sets the template for editing a topic.
If these preferences are set locally (using Local instead of Set) for a topic, in WebPreferences, in Main.TWikiPreferences, or TWiki.TWikiPreferences (using Set), the indicated templates will be chosen for view and edit respectively. The template search order is as specified above. |
|
> > | TMPL:INCLUDE recusion for piecewise customisation, or mixing in new features
If there is recusion in the TMPL:INCLUDE chain (eg twiki.classic.tmpl contains %TMPL:INCLUDE{"twiki"}% , the templating system will include the next twiki.SKIN in the skin path.
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:
%TMPL:INCLUDE{"view"}%
%TMPL:DEF{"breadcrumb"}% We don't want any crumbs %TMPL:END%
and then set SKIN=yourlocal,pattern |
| Master Templates
Master 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.
|
|
|
|
< < |
%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%{...}% |
|
> > |
%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 %URLPA%NOP%RAM{...}% escaping URLPARAM |
|
|
%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 |
|
|
Automatically Generated Topicname |
|
< < | If 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. |
> > | For TWiki application it is useful 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, it gets 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.
Examples:
-
BugAUTOINC0 - creates topic names Bug0 , Bug1 , Bug2 , ... (does not sort properly)
-
ItemAUTOINC0000 - creates topic names Item0000 , Item0001 , Item0002 , ... (sorts properly up to 9999)
-
DocIDAUTOINC10001 - start with DocID10001 , DocID10002 , ... (sorts properly up to 99999; auto-links)
|
| Example link to create a new topic:
|
|
< < | Create new item= |
> > | Create new item= |
|
Master Templates by Example |
| The 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"}%
|
|
< < | |
|
%TMPL:DEF{"sep"}% | %TMPL:END%
<html>
|
| </table>
</body>
|
|
< < | |
|
Test template oopstest.tmpl |
| Each oops template basically just defines some variables and includes the base template that does the layout work.
|
|
< < | |
|
%TMPL:DEF{"titleaction"}% (test =titleaction=) %TMPL:END%
%TMPL:DEF{"webaction"}% test =webaction= %TMPL:END%
|
| [[%TWIKIWEB%.TWikiRegistration][Register]] %TMPL:END%
%TMPL:INCLUDE{"oopsbase"}%
|
|
< < | |
|
Sample screen shot of oopstest.tmpl
With URL: .../bin/oops/Sandbox/TestTopic2?template=oopstest¶m1=WebHome¶m2=WebNotify |
|
< < |
|
> > | |
| Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory |