Welcome, Registration, and other StartingPoints; TWiki history & Wiki style; All the docs...
View   r26  >  r25  ...
TWikiTemplates 26 - 28 Nov 2006 - Main.TWikiContributor
Line: 1 to 1
 

TWiki Templates

Line: 14 to 14
 All three types of template use the TWiki template system.
Added:
>
>
TIP 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.

Line: 24 to 26
 
  • 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.
Changed:
<
<
    • %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.
Line: 64 to 66
 
  1. templates/web/script.tmpl
    • ALERT! this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
  2. templates/script.tmpl
Changed:
<
<
  1. The TWiki topic web.topic if the template name can be parsed into web.topic
>
>
  1. The TWiki topic aweb.atopic if the template name can be parsed into aweb.atopic
 
  1. The TWiki topic web.SkinSkinScriptTemplate for each skin on the skin path
  2. The TWiki topic web.ScriptTemplate
Changed:
<
<
  1. The TWiki topic TWiki.SkinSkinScriptTemplate for each skin on the skin path
  2. The TWiki topic TWiki.ScriptTemplate
>
>
  1. The TWiki topic %TWIKIWEB%.SkinSkinScriptTemplate for each skin on the skin path
  2. 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
Line: 95 to 97
 
  • 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.
Added:
>
>

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.
Line: 143 to 155
 
%DATE% Signature format date. See VarDATE
%GMTIME% Date/time. See VarGMTIME
%GMTIME{...}% Formatted date/time. See VarGMTIME2
Changed:
<
<
%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
Line: 203 to 215
 

Automatically Generated Topicname

Changed:
<
<
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:
Changed:
<
<
Create new item=
>
>
Create new item=
 

Master Templates by Example

Line: 219 to 236
 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"}%

Deleted:
<
<
 
%TMPL:DEF{"sep"}% | %TMPL:END%
<html>

Line: 260 to 275
 </table> </body>
Deleted:
<
<
 

Test template oopstest.tmpl

Line: 269 to 282
 Each oops template basically just defines some variables and includes the base template that does the layout work.

Deleted:
<
<
 
%TMPL:DEF{"titleaction"}% (test =titleaction=) %TMPL:END%
%TMPL:DEF{"webaction"}% test =webaction= %TMPL:END%

Line: 291 to 302
 [[%TWIKIWEB%.TWikiRegistration][Register]] %TMPL:END% %TMPL:INCLUDE{"oopsbase"}%
Deleted:
<
<
 

Sample screen shot of oopstest.tmpl

With URL: .../bin/oops/Sandbox/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify

Changed:
<
<
testscreen.gif
>
>
testscreen.gif
 Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory

Revision 26r26 - 28 Nov 2006 - 01:13:08 - TWikiContributor
Revision 25r25 - 27 Mar 2005 - 13:14:15 - TWikiContributor
This site is powered by the TWiki collaboration platform.
All material on this collaboration platform is the property of the contributing authors.
All material marked as authored by Eben Moglen is available under the license terms CC-BY-SA version 4.
Syndicate this site RSSATOM