Difference: TWikiTemplates (1 vs. 37)

Revision 372013-09-25 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 118 to 118
 TIP Tip: If you want to override existing templates, without having to worry that your changes will get overwritten by the next TWiki update, change the {TemplatePath} so that another directory, such as the %USERSWEB% appears at the front. You can then put your own templates into that directory or web and these will override the standard templates. (Note that such will increase the lookup time for templates by searching your directory first.)

Changed:
<
<

TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features

>
>

TMPL:INCLUDE recursion for piecewise customization, or mixing in new features

  If there is recursion 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.
Changed:
<
<
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:
>
>
For example, to create a customization 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%
Line: 199 to 199
 %NOP% can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation. For example, escape %SERVERTIME% with %SER%NOP%VERTIME%.

Changed:
<
<

3. Control over variable expansion

>
>

3. Causing variable expansion in a section

  You can forcefully expand TWikiVariables by placing them inside a type="expandvariables" section in the template topic, such as:
Line: 229 to 229
 
Added:
>
>

4. Specifying variables to be expanded individually

You may want to mix variables to be expanded and variables not to be. By prepending a variable name with EOTC__ (EOTC followed by two underscores; EOTC stands for Expand On Topic Creation), you can have the variable expanded.

Here's an example.

%EOTC__SEARCH{"."
 topic="%URLPARAM{prefix}%*"
 nonoise="on"
 format="$percntINCLUDE{$topic}$percnt" separator="$n"
}%
This yields a series of %INCLUDE{...}%s, which are not expanded. This is not achievable by an expandvariables section.
 

Specifying a Form

Line: 265 to 281
  Here is an example for creating new topics (in the Sandbox web) based on a specific template topic and form:
Changed:
<
<
>
>
 
  • New example topic:
Changed:
<
<
 
>
>

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 raw text of the form:

%EDITFORMFIELD{ "new" type="start" action="edit" topic="Sandbox.%TOPIC%" }%
   * New example topic: 
     %EDITFORMFIELD{ "topic" type="text" value="ExampleTopicAUTOINC0001" size="30" }%
     %EDITFORMFIELD{ "templatetopic" type="hidden" value="%SYSTEMWEB%.ExampleTopicTemplate" }%
     %EDITFORMFIELD{ "topicparent" type="hidden" value="%HOMETOPIC%" }%
     %EDITFORMFIELD{ "onlywikiname" type="hidden" value="on" }%
     %EDITFORMFIELD{ "onlynewtopic" type="hidden" value="on" }%
     %EDITFORMFIELD{ "form" type="submit" value="Create" }%
%EDITFORMFIELD{ "form" type="end" }%
 
Changed:
<
<
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:
>
>
Here is the equivalent form using a hand-crafted HTML form:
 

Changed:
<
<
<form name="new" action="%SCRIPTURLPATH{edit}%/Sandbox/">
>
>
<form name="new" action="%SCRIPTURLPATH{edit}%/Sandbox/%HOMETOPIC%">
 
  • New example topic: <input type="text" name="topic" value="ExampleTopicAUTOINC0001" size="30" />
Changed:
<
<
<input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> <input type="hidden" name="topicparent" value="%TOPIC%" />
>
>
<input type="hidden" name="templatetopic" value="%SYSTEMWEB%.ExampleTopicTemplate" /> <input type="hidden" name="topicparent" value="%HOMETOPIC%" />
  <input type="hidden" name="onlywikiname" value="on" /> <input type="hidden" name="onlynewtopic" value="on" /> <input type="submit" class="twikiSubmit" value="Create" /> </form>
Changed:
<
<
ALERT! Note: You can create a topic in one step, without going through the edit screen. To do that, specify the save script instead of the edit script in the form action. When you specify the save script you have to use the "post" method. Example:
>
>
ALERT! Note: You can create a topic in one step, without going through the edit screen. To do that, specify the save script instead of the edit script in the form action. When you specify the save script in an HTML form tag you have to use the "post" method. This is done automatically when using the EDITFORMFIELD variable. Example when using the HTML form tag:
 
<form name="new" action="%SCRIPTURLPATH{save}%/Sandbox/" method="post">
    ...

Revision 362012-05-17 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 59 to 59
 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.
Added:
>
>
 

Finding Templates

The master templates shipped with a twiki release are stored in the twiki/templates directory.

Line: 116 to 117
  TIP Tip: If you want to override existing templates, without having to worry that your changes will get overwritten by the next TWiki update, change the {TemplatePath} so that another directory, such as the %USERSWEB% appears at the front. You can then put your own templates into that directory or web and these will override the standard templates. (Note that such will increase the lookup time for templates by searching your directory first.)
Added:
>
>
 

TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features

If there is recursion 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.

Line: 128 to 130
  The default {TemplatePath} will not give you the desired result if you put these statements in the topic Thisweb.YourlocalSkinViewTemplate. The default {TemplatePath} will resolve the request to the template/view.pattern.tmpl, before it gets to the Thisweb.YourlocalSkinViewTemplate resolution. You can make it work by prefixing the {TemplatePath} with: $web.YourlocalSkin$nameTemplate.
Added:
>
>
 

Default master template

twiki.tmpl is the default master template. It defines the following sections.

Line: 158 to 161
 
  1. WebTopicEditTemplate in the TWiki web

Added:
>
>
 

Variable Expansion

TWikiVariables located in template topics get expanded as follows when a new topic is created.

Line: 244 to 248
 
  • ItemAUTOINC0000 - creates topic names Item0000, Item0001, Item0002, ... (sorts properly up to 9999)
  • DocIDAUTOINC10001 - start with DocID10001, DocID10002, ... (sorts properly up to 99999; auto-links)
Added:
>
>
Characters after AUTOINC<n> are preserved, but are not taken into account when calculating the next increment. Use this to create topic names that have a unique identifier (serial number) and a descriptive text.

Example:

  • BlogAUTOINC0001-my-first-blog - creates topic name Blog0001-my-first-blog
  • BlogAUTOINC0001-my-crazy-cats - creates topic name Blog0002-my-crazy-cats
  • BlogAUTOINC0001-fondue-recipe - creates topic name Blog0003-fondue-recipe
 Example link to create a new topic:
[[%SCRIPTURLPATH{edit}%/%WEB%/BugIDAUTOINC00001?templatetopic=BugTemplate;topicparent=%TOPIC%;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]
Added:
>
>
 

Template Topics in Action

Here is an example for creating new topics (in the Sandbox web) based on a specific template topic and form:

Line: 288 to 300
 TIP 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%
Added:
>
>
 

Using Absolute vs Relative URLs in Templates

When you use TWikiVariables such as %PUBURL% and %PUBURLPATH% in templates you should be aware that using %PUBURL% instead of %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 %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.

Revision 352010-09-20 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 154 to 154
 
  1. A topic name specified by the templatetopic CGI parameter
    • if no web is specified, the current web is searched first and then the TWiki web
  2. WebTopicEditTemplate in the current web
Added:
>
>
  1. WebTopicEditTemplate in the Main web
 
  1. WebTopicEditTemplate in the TWiki web

Revision 342010-09-20 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 114 to 114
 
  • 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:
>
>
TIP Tip: If you want to override existing templates, without having to worry that your changes will get overwritten by the next TWiki update, change the {TemplatePath} so that another directory, such as the %USERSWEB% appears at the front. You can then put your own templates into that directory or web and these will override the standard templates. (Note that such will increase the lookup time for templates by searching your directory first.)
 

TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features

If there is recursion 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.

Revision 332010-05-16 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 204 to 204
 If you have the following content in a template topic:
%STARTSECTION{ type="expandvariables" }%
Changed:
<
<
>
>
 
Line: 215 to 215
 you will get this raw text in new topics based on that template topic:


Changed:
<
<
>
>
 

Revision 322009-04-17 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 273 to 273
 </form>
Changed:
<
<
See TWikiScripts#edit for details of the parameters that the edit script understands.
>
>
ALERT! Note: You can create a topic in one step, without going through the edit screen. To do that, specify the save script instead of the edit script in the form action. When you specify the save script you have to use the "post" method. Example:
<form name="new" action="%SCRIPTURLPATH{save}%/Sandbox/" method="post">
    ...
</form>

HELP The edit and save scripts understand many more parameters, see TWikiScripts#edit and TWikiScripts#save for details.

  TIP 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%
Line: 282 to 289
  When you use TWikiVariables such as %PUBURL% and %PUBURLPATH% in templates you should be aware that using %PUBURL% instead of %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 %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.
Changed:
<
<
Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
>
>
Related Topics: TWikiSkins, TWikiForms, TWikiScripts, DeveloperDocumentationCategory, AdminDocumentationCategory
 

-- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie, TWiki:Main.SopanShewale

Revision 312009-01-31 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 157 to 157
 

Variable Expansion

Changed:
<
<
When the following variables are used in a template topic, they automatically get expanded when new topic is created based on it:
>
>
TWikiVariables located in template topics get expanded as follows when a new topic is created.

1. Default variable expansion

The following variables used in a template topic automatically get expanded when new topic is created based on it:

 
Variable: Description:
%DATE% Signature format date. See VarDATE
Line: 168 to 173
 
%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
Changed:
<
<
%URLPARAM{"name"}% Value of a named URL parameter
>
>
%URLPARAM{"name"}% Value of a named URL parameter. See VarURLPARAM.
 
%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
Changed:
<
<
%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:
>
>

2. Preventing variable expansion

In a template topic, embed text that you do not want expanded inside a %STARTSECTION{type="templateonly"}% ... %ENDSECTION{type="templateonly"}% section. For example, you might want to write this in the template topic:

 
%STARTSECTION{type="templateonly"}%
This template can only be changed by:
   * Set ALLOWTOPICCHANGE = Main.TWikiAdminGroup
%ENDSECTION{type="templateonly"}%
Changed:
<
<
This will restrict who can edit the template topic, but will get removed when a new topic based on that template topic is created.
>
>
This will restrict who can edit the template topic, but will be 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. For example, escape %SERVERTIME% with %SER%NOP%VERTIME%.

 
Changed:
<
<
%NOP% can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation e.g.i escape %SERVERTIME% with %SER%NOP%VERTIME%.
>
>

3. Control over variable expansion

 
Changed:
<
<
All other variables are unchanged, e.g. are carried over "as is" into the new topic.
>
>
You can forcefully expand TWikiVariables by placing them inside a type="expandvariables" section in the template topic, such as:
%STARTSECTION{ type="expandvariables" }% ... %ENDSECTION{ type="expandvariables" }% 
 
Added:
>
>
Example:

If you have the following content in a template topic:

%STARTSECTION{ type="expandvariables" }%
   * %TWIKIWEB%.ATasteOfTWiki - view a short introductory presentation on TWiki for beginners
   * %TWIKIWEB%.WelcomeGuest - starting points on TWiki
   * %TWIKIWEB%.TWikiUsersGuide - complete TWiki documentation
   * Sandbox.%HOMETOPIC% - try out TWiki on your own
   * Sandbox.%TOPIC%Sandbox - just for me
%ENDSECTION{ type="expandvariables" }%

you will get this raw text in new topics based on that template topic:

   * TWiki.ATasteOfTWiki - view a short introductory presentation on TWiki for beginners
   * TWiki.WelcomeGuest - starting points on TWiki
   * TWiki.TWikiUsersGuide - complete TWiki documentation
   * Sandbox.WebHome - try out TWiki on your own
   * Sandbox.JimmyNeutronSandbox - just for me

 

Specifying a Form

Added:
>
>
 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.

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.

Line: 246 to 285
 Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
Changed:
<
<
-- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie
>
>
-- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie, TWiki:Main.SopanShewale

Revision 302008-05-17 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 18 to 18
 

Master Templates

Changed:
<
<
TWiki uses master 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.
>
>
TWiki uses master 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.
  Master templates are also used in the definition of TWikiSkins.
Changed:
<
<
Master templates are stored as text files with the extension .tmpl. They are usually HTML with embedded template directives. The directives are expanded when TWiki wants to generate a user interface screen.
>
>
Master templates are stored as text files with the extension .tmpl. They are usually HTML with embedded template directives. The directives are expanded when TWiki wants to generate a user interface screen.
 

How Template Directives Work

Line: 43 to 46
  Note that parameters can simply be ignored; for example, %TMPL:P{"x"}% will expand to x%P%z.
Changed:
<
<
Any alphanumeric characters can be used in parameter names. You are highly recommended to use parameter names that cannot be confused with TWikiVariables.
>
>
Any alphanumeric characters can be used in parameter names. You are highly recommended to use parameter names that cannot be confused with TWikiVariables.
 
Changed:
<
<
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:
>
>
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%
Line: 56 to 61
 

Finding Templates

Changed:
<
<
The master templates shipped with a twiki release are stored in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the default template file for the twiki/bin/view script.
>
>
The master templates shipped with a twiki release are stored in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the default template file for the twiki/bin/view script.
 
Changed:
<
<
You can save templates in other directories as long as they are listed in the {TemplatePath} configuration setting. The {TemplatePath} is defined in the Miscellaneous section of the configure page.
>
>
You can save templates in other directories as long as they are listed in the {TemplatePath} configuration setting. The {TemplatePath} is defined in the Miscellaneous section of the configure page.
 
Changed:
<
<
You can also save templates in user topics. The {TemplatePath} configuration setting defines which topics will be accepted as templates.
>
>
You can also save templates in user topics (IF there is no possible template match in the templates directory). The {TemplatePath} configuration setting defines which topics will be accepted as templates.
 
Changed:
<
<
Templates that are included with an explicit '.tmpl' extension are looked for only in the templates/ directory. For instance %TMPL:INCLUDE{"example.tmpl"}% will only return templates/example.tmpl, regardless of {TemplatePath} and SKIN settings.
>
>
Templates that are included with an explicit '.tmpl' extension are looked for only in the templates/ directory. For instance %TMPL:INCLUDE{"example.tmpl"}% will only return templates/example.tmpl, regardless of {TemplatePath} and SKIN settings.
 
Changed:
<
<
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. The skin path is set as described in TWikiSkins.
>
>
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. The skin path is set as described in TWikiSkins.
 
  1. templates/web/script.skin.tmpl for each skin on the skin path
    • ALERT! this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.

Revision 292008-05-17 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 130 to 130
 

Template Topics

Changed:
<
<
The second type of template in TWiki are template topics. Template topics define the default text for new topics. There are three types of template topic:
>
>
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:
 
Topic Name: What it is:
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.
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.
WebTopicEditTemplate Default text used in a new topic.
Added:
>
>
<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.
  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:
  1. A topic name specified by the templatetopic CGI parameter

Revision 282007-12-05 - TWikiContributor

Line: 1 to 1
Deleted:
<
<
 
Changed:
<
<

TWiki Templates

>
>

TWiki Templates

  Definition of the templates used to render all HTML pages displayed in TWiki
Added:
>
>
 

Overview

Changed:
<
<
There are three types of template:
  • Master Templates: Define blocks of text for use in other templates
  • HTML Page Templates: Define the layout of URCS pages
  • Template Topics: Define default text when you create a new topic
>
>
Templates are plain text with embedded template directives that tell TWiki how to compose blocks of text together, to create something new.
 
Changed:
<
<
All three types of template use the TWiki template system.
>
>
There are two types of template:
  • Master Templates: Define the HTML used to display TWiki pages.
  • Template Topics: Define default text when you create a new topic
  TIP Tip: TWiki:TWiki.TWikiTemplatesSupplement on TWiki.org has supplemental documentation on TWiki templates.
Changed:
<
<

The TWiki Template System

>
>

Master Templates

TWiki uses master 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.
 
Changed:
<
<
Templates are plain text with embedded template directives that tell TWiki how to compose blocks of text together to create something new.
>
>
Master templates are also used in the definition of TWikiSkins.

Master templates are stored as text files with the extension .tmpl. They are usually HTML with embedded template directives. The directives are expanded when TWiki wants to generate a user interface screen.

 

How Template Directives Work

Deleted:
<
<
  • Template directives are embedded in templates.
 
  • 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.
Line: 38 to 41
 TMPL:P also supports simple parameters. For example, given the definition %TMPL:DEF{"x"}% x%P%z%TMPL:END% then %TMPL:P{"x" P="y"}% will expand to xyz.
Changed:
<
<
Note that parameters can simply be ignored; for example=%TMPL:P{"x"}%= will expand to x%P%z.
>
>
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.
Line: 53 to 56
 

Finding Templates

Changed:
<
<
Templates are stored either in the 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.
>
>
The master templates shipped with a twiki release are stored in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the default template file for the twiki/bin/view script.

You can save templates in other directories as long as they are listed in the {TemplatePath} configuration setting. The {TemplatePath} is defined in the Miscellaneous section of the configure page.

 
Changed:
<
<
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.
>
>
You can also save templates in user topics. The {TemplatePath} configuration setting defines which topics will be accepted as templates.
 
Changed:
<
<
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.
>
>
Templates that are included with an explicit '.tmpl' extension are looked for only in the templates/ directory. For instance %TMPL:INCLUDE{"example.tmpl"}% will only return templates/example.tmpl, regardless of {TemplatePath} and SKIN settings.

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. The skin path is set as described in TWikiSkins.

 
Deleted:
<
<
 
  1. templates/web/script.skin.tmpl for each skin on the skin path
    • ALERT! this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
  2. templates/script.skin.tmpl for each skin on the skin path
Line: 69 to 75
 
  1. The TWiki topic aweb.atopic if the template name can be parsed into aweb.atopic
  2. The TWiki topic web.SkinSkinScriptTemplate for each skin on the skin path
  3. The TWiki topic web.ScriptTemplate
Changed:
<
<
  1. The TWiki topic %TWIKIWEB%.SkinSkinScriptTemplate for each skin on the skin path
  2. The TWiki topic %TWIKIWEB%.ScriptTemplate
>
>
  1. The TWiki topic %SYSTEMWEB%.SkinSkinScriptTemplate for each skin on the skin path
  2. The TWiki topic %SYSTEMWEB%.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
  • 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
Changed:
<
<
>
>
 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:
Added:
>
>
 
  1. templates/Thisweb/example.print.tmpl deprecated; don't rely on it
  2. templates/Thisweb/example.pattern.tmpl deprecated; don't rely on it
  3. templates/example.print.tmpl
Line: 88 to 95
 
  1. Thisweb.PrintSkinExampleTemplate
  2. Thisweb.PatternSkinExampleTemplate
  3. Thisweb.ExampleTemplate
Changed:
<
<
  1. TWiki.PrintSkinExampleTemplate
  2. TWiki.PatternSkinExampleTemplate
  3. TWiki.ExampleTemplate
>
>
  1. TWiki.PrintSkinExampleTemplate
  2. TWiki.PatternSkinExampleTemplate
  3. TWiki.ExampleTemplate
 
Changed:
<
<
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 user to override the templates used:
>
>
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:
 
  • VIEW_TEMPLATE sets the template to be used for viewing a topic
  • EDIT_TEMPLATE sets the template for editing a topic.
Changed:
<
<
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.
>
>
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.
 
Changed:
<
<

TMPL:INCLUDE recusion for piecewise customisation, or mixing in new features

>
>

TMPL:INCLUDE recursion for piecewise customisation, or mixing in new features

 
Changed:
<
<
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.
>
>
If there is recursion 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"}%
Line: 107 to 114
  and then set SKIN=yourlocal,pattern
Changed:
<
<

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.
>
>
The default {TemplatePath} will not give you the desired result if you put these statements in the topic Thisweb.YourlocalSkinViewTemplate. The default {TemplatePath} will resolve the request to the template/view.pattern.tmpl, before it gets to the Thisweb.YourlocalSkinViewTemplate resolution. You can make it work by prefixing the {TemplatePath} with: $web.YourlocalSkin$nameTemplate.

Default master template

twiki.tmpl is the default master template. It defines the following sections.

 
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
Deleted:
<
<
%TMPL:DEF{"oops"}% Skeleton of oops dialog

HTML Page Templates

HTML 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 Topics

Changed:
<
<
Template topics define the default text for new topics. There are three types of template topic:
>
>
The second type of template in TWiki are template topics. Template topics define the default text for new topics. There are three types of template topic:
 
Topic Name: What it is:
Changed:
<
<
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.
When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:

  1. A topic name specified by the templatetopic CGI parameter
    • if no web is specified, the current web is searched first and then the TWiki web
  2. WebTopicEditTemplate in the current web
  3. WebTopicEditTemplate in the TWiki web
>
>
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.
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.
WebTopicEditTemplate Default text used in a new topic.

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:

  1. A topic name specified by the templatetopic CGI parameter
    • if no web is specified, the current web is searched first and then the TWiki web
  2. WebTopicEditTemplate in the current web
  3. WebTopicEditTemplate in the TWiki web
 
Changed:
<
<

Edit Template Topics and Variable Expansion

>
>

Variable Expansion

 
Changed:
<
<
The following variables get expanded when a user creates a new topic based on a template topic:
>
>
When the following variables are used in a template topic, they automatically get expanded when new topic is created based on it:
 
Deleted:
<
<
 
Variable: Description:
%DATE% Signature format date. See VarDATE
%GMTIME% Date/time. See VarGMTIME
Line: 163 to 160
 
%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
Deleted:
<
<
  %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:
Changed:
<
<
%STARTSECTION{type="templateonly"}%
>
>
%STARTSECTION{type="templateonly"}%

 This template can only be changed by:
Changed:
<
<

>
>
  • Set ALLOWTOPICCHANGE = Main.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.
Changed:
<
<
%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%.
>
>
%NOP% can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation e.g.i escape %SERVERTIME% with %SER%NOP%VERTIME%.
  All other variables are unchanged, e.g. are carried over "as is" into the new topic.
Added:
>
>

Specifying a Form

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.

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.

See TWikiScripts for information about all the other parameters to edit.

Automatically Generated Topic Names

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.

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:

[[%SCRIPTURLPATH{edit}%/%WEB%/BugIDAUTOINC00001?templatetopic=BugTemplate;topicparent=%TOPIC%;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]
 

Template Topics in Action

Changed:
<
<
Here is an example for creating new topics based on a specific template topic:
>
>
Here is an example for creating new topics (in the Sandbox web) based on a specific template topic and form:
 
Changed:
<
<
>
>
 
  • New example topic:
Changed:
<
<
 
>
>
 
 
Deleted:
<
<
(date format is YYYYxMMxDD)
 

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:


Changed:
<
<
<form name="new" action="%SCRIPTURLPATH{edit}%/%WEB%/">
>
>
<form name="new" action="%SCRIPTURLPATH{edit}%/Sandbox/">
 
  • New example topic:
Changed:
<
<
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="26" />
>
>
<input type="text" name="topic" value="ExampleTopicAUTOINC0001" size="30" />
  <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" />
Deleted:
<
<
(date format is <nop>YYYYxMMxDD)
 </form>
Line: 212 to 228
 TIP 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%
Changed:
<
<

Automatically Generated Topicname

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.

>
>

Using Absolute vs Relative URLs in Templates

 
Changed:
<
<
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:

[[%SCRIPTURLPATH{"edit"}%/%WEB%/BugIDAUTOINC00000?templatetopic=BugTemplate&amp;topicparent=%TOPIC%&amp;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]=

Master Templates by Example

Attached is an example of an oops based template oopsbase.tmpl and an example oops dialog oopstest.tmpl based on the base template. TIP NOTE: This isn't the release version, just a quick, simple demo.

Base template oopsbase.tmpl

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>
<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>

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%
%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"}%

Sample screen shot of oopstest.tmpl

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

testscreen.gif

>
>
When you use TWikiVariables such as %PUBURL% and %PUBURLPATH% in templates you should be aware that using %PUBURL% instead of %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 %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.
  Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
Changed:
<
<
-- Contributors: TWiki:Main.CrawfordCurrie, TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc

META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="TWikiContributor" version="1.2"
>
>
-- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie

Revision 272007-02-16 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 111 to 111
 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.
Template variable: Defines:
Changed:
<
<
%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
>
>
%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
 

Line: 207 to 207
 </form>
Changed:
<
<
See TWikiScripts for details of the parameters that the edit script understands.
>
>
See TWikiScripts#edit for details of the parameters that the edit script understands.
  TIP 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%
Line: 312 to 312
  Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
Added:
>
>
-- Contributors: TWiki:Main.CrawfordCurrie, TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="TWikiContributor" version="1.2"

Revision 262006-11-28 - 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 252005-03-27 - TWikiContributor

Line: 1 to 1
 

TWiki Templates

Line: 140 to 140
 
Variable: Description:
Changed:
<
<
%DATE% Signature format date. See TWikiVariables#VarDATE
%GMTIME% Date/time. See TWikiVariables#VarGMTIME
%GMTIME{...}% Formatted date/time. See TWikiVariables#VarGMTIME2
>
>
%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.
Changed:
<
<
%SERVERTIME% Date/time. See TWikiVariables#VarSERVERTIME
%SERVERTIME{...}% Formatted date/time. See TWikiVariables#VarSERVERTIME2
>
>
%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

Revision 242005-03-27 - TWikiContributor

Line: 1 to 1
Deleted:
<
<
META TOPICPARENT name="WebHome"
 

TWiki Templates

Line: 8 to 7
 

Overview

Changed:
<
<
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML markup for template-specific content. Templates are used to define page layout, and also to supply default content for new pages.
>
>
There are three types of template:
  • Master Templates: Define blocks of text for use in other templates
  • HTML Page Templates: Define the layout of URCS pages
  • Template Topics: Define default text when you create a new topic
 
Changed:
<
<

Major changes from the previous template system

>
>
All three types of template use the TWiki template system.
 
Changed:
<
<
Where the old templates were each complete HTML documents, the new templates are defined using variables to include template parts from a master file. You can now change one instance of a common element to update all occurrences; previously, every affected template had to be updated. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for TWikiSkins. The new system:
>
>

The TWiki Template System

 
Changed:
<
<
  • separates a set of common template parts into a base template that is included by all of the related templates;
  • defines common variables, like a standard separator (ex: "|"), in the base template;
  • defines variable text in the individual templates and passes it back to the base template.
>
>
Templates are plain text with embedded template directives that tell TWiki how to compose blocks of text together to create something new.
 
Changed:
<
<

How Template Variables Work

  • Special template directives (or preprocessor commands) are embedded in normal templates.
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before).
>
>

How Template Directives Work

  • Template directives are embedded in templates.
 
  • Directives are of the form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
  • Directives:
Changed:
<
<
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The template directory of the current web is searched first, then the templates root (twiki/templates).
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
  • Variables live in a global name space: there is no parameter passing.
>
>
    • %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.
 
  • Two-pass processing lets you use a variable before or after declaring it.
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads only the twiki.tmpl master template, like twiki.print.tmpl, that redefines the header and footer.
  • HELP Use of template directives is optional: templates work without them.
Changed:
<
<
  • ALERT! NOTE: Template directives work only for templates: they do not get processed in topic text.
>
>
  • ALERT! NOTE: Template directives work only for templates: they do not get processed in normal topic text.
 
Changed:
<
<

Types of Template

>
>
TMPL:P also supports simple parameters. For example, given the definition %TMPL:DEF{"x"}% x%P%z%TMPL:END% then %TMPL:P{"x" P="y"}% will expand to xyz.
 
Changed:
<
<
There are three types of template:
>
>
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.

 
Changed:
<
<
  • Master Template: Stores common parts; included by other templates
  • HTML Page Templates: Defines the layout of URCS pages
  • Template Topics: Defines default text when you create a new topic
>
>
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.
 
Changed:
<
<

Master Templates

>
>

Finding Templates

Templates are stored either in the 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.

 
Changed:
<
<
Common parts, appearing in two or more templates, can be defined in a master template and then shared by others: twiki.tmpl is the default master template.
>
>
  1. templates/web/script.skin.tmpl for each skin on the skin path
    • ALERT! this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
  2. templates/script.skin.tmpl for each skin on the skin path
  3. templates/web/script.tmpl
    • ALERT! this usage is supported for compatibility only and is deprecated. Store web-specific templates in TWiki topics instead.
  4. templates/script.tmpl
  5. The TWiki topic web.topic if the template name can be parsed into web.topic
  6. The TWiki topic web.SkinSkinScriptTemplate for each skin on the skin path
  7. The TWiki topic web.ScriptTemplate
  8. The TWiki topic TWiki.SkinSkinScriptTemplate for each skin on the skin path
  9. The TWiki topic TWiki.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
  • 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
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:
  1. templates/Thisweb/example.print.tmpl deprecated; don't rely on it
  2. templates/Thisweb/example.pattern.tmpl deprecated; don't rely on it
  3. templates/example.print.tmpl
  4. templates/example.pattern.tmpl
  5. templates/Thisweb/example.tmpl deprecated; don't rely on it
  6. templates/example.tmpl
  7. Thisweb.PrintSkinExampleTemplate
  8. Thisweb.PatternSkinExampleTemplate
  9. Thisweb.ExampleTemplate
  10. TWiki.PrintSkinExampleTemplate
  11. TWiki.PatternSkinExampleTemplate
  12. TWiki.ExampleTemplate

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 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.
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.

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.
 
Template variable: Defines:
%TMPL:DEF{"sep"}% "|" separator
Line: 57 to 108
 

Changed:
<
<

HTML Page Templates

TWiki uses HTML template files for 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.

Templates are stored either in the twiki/templates directory or in user topics. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script.

>
>

HTML Page Templates

 
Changed:
<
<
HELP Templates can be overloaded by individual webs.
>
>
HTML 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.
 
Changed:
<
<
HELP TWikiSkins can overload the standard templates.
>
>
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.
 
Changed:
<
<
TWiki uses the following search order to determine which template to use:

If a skin is specified If no skin is specified
templates/%WEB%/script.skin.tmpl templates/%WEB%/script.tmpl
templates/script.skin.tmpl templates/script.tmpl
data/%WEB%/SkinSkinScriptTemplate.txt data/%WEB%/ScriptTemplate.txt
data/TWiki/SkinSkinScriptTemplate.txt data/TWiki/ScriptTemplate.txt
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
skin refers to the skin name, e.g dragon, pattern
Skin refers to the same, but with the first character capitalized, e.g Dragon
%WEB% refers to the current web

Additionally (and primarily for use in %TMPL:INCLUDE{}%) the template name may be a wiki topic name, specified as Web.Topic, in which case the search is:

If a skin is specified If no skin is specified
templates/web/Web.Topic.skin.tmpl templates/web/Web.Topic.tmpl
templates/Web.Topic.skin.tmpl templates/Web.Topic.tmpl
data/Web/Topic.txt
If Web is not specified in the INCLUDE, it defaults to TWiki, and the search to the first type.

Special variables are used in templates, especially in view, to display meta data.

>
>
HTML page templates are also used in the definition of TWikiSkins.
 
Changed:
<
<

Template Topics

>
>

Template Topics

  Template topics define the default text for new topics. There are three types of template topic:
Line: 99 to 126
 
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.
Changed:
<
<
All template topics are located in the TWiki web. The WebTopicEditTemplate can be overloaded. When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:
>
>
When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:
 
Changed:
<
<
  1. A topic name specified by the templatetopic CGI parameter.
>
>
  1. A topic name specified by the templatetopic CGI parameter
    • if no web is specified, the current web is searched first and then the TWiki web
 
  1. WebTopicEditTemplate in the current web
  2. WebTopicEditTemplate in the TWiki web
Changed:
<
<

Edit Template Topics and Variable Expansion

>
>

Edit Template Topics and Variable Expansion

  The following variables get expanded when a user creates a new topic based on a template topic:

Variable: Description:
Changed:
<
<
%DATE% Current date, e.g. 2018-11-18
%USERNAME% Login name, e.g. jsmith
%WIKINAME% WikiName of user, e.g. JohnSmith
%WIKIUSERNAME% User name, e.g. Main.JohnSmith
%URLPARAM{"name"}% Value of a named URL parameter
>
>
%DATE% Signature format date. See TWikiVariables#VarDATE
%GMTIME% Date/time. See TWikiVariables#VarGMTIME
%GMTIME{...}% Formatted date/time. See TWikiVariables#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%{...}%
Changed:
<
<
%NOP{ ... }% A no-operation text that gets removed. Useful to write-protect an edit template topic, but not the topics based this template topic. See notes below. Example:
%NOP{
   * Set ALLOWTOPICCHANGE = Main.TWikiAdminGroup
  }%
>
>
%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 TWikiVariables#VarSERVERTIME
%SERVERTIME{...}% Formatted date/time. See TWikiVariables#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
 
Changed:
<
<
Notes:
  • Unlike other variables, %NOP{ ... }% can span multiple lines.
  • The scan for the closing }% pattern is "non-greedy", that is, it stops at the first occurance. That means, you need to escape variables with parameters located inside %NOP{ ... }%: Insert a %NOP% between } and %. Silly example: %NOP{ %GMTIME{"$year"}%NOP%% }%.
>
>
%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.
Changed:
<
<

Template Topics in Action

>
>

Template Topics in Action

  Here is an example for creating new topics based on a specific template topic:
Changed:
<
<
>
>
 
  • New example topic:
Changed:
<
<
>
>
 
 
Deleted:
<
<
  (date format is YYYYxMMxDD)

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:


Changed:
<
<
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%"}%/">
>
>
<form name="new" action="%SCRIPTURLPATH{edit}%/%WEB%/">
 
  • New example topic:
Changed:
<
<
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" />
>
>
<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" />
Changed:
<
<
<input type="submit" value="Create" />
>
>
<input type="submit" class="twikiSubmit" value="Create" />
  (date format is <nop>YYYYxMMxDD) </form>
Changed:
<
<
The edit scipt understands the following parameters, typically supplied by HTML input fields:

Parameter: Description:
topic Name of topic to create. Can be set in a text field, or is set programmatically (e.g. with a sequential number)
onlywikiname If set, TWiki will complain if the topic name is not a WikiWord
onlynewtopic If set, TWiki will complain if a topic of the same name already exists
templatetopic The name of the template topic, e.g. topic used to copy the initial content
topicparent Sets the parent topic
TopicClassification Assuming the template topic has a form with a field called "TopicClassification", it will set the value of the field
contenttype Optional parameter that defines the application type to write into the CGI header. Defaults to text/html. May be used to invoke alternative client applications
anyname Any parameter can passed to the new topic; if the template topic contains %URLPARAM{"anyname"}%, it will be replaced by its value
>
>
See TWikiScripts for details of the parameters that the edit script understands.
  TIP 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%
Changed:
<
<

Templates by Example

>
>

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.

 
Changed:
<
<
Attached is an example of an oops based template oopsbase.tmpl and an example oops dialog oopstest.tmpl based on the base template. %A% NOTE: This isn't the release version, just a quick, simple demo.
>
>
Example link to create a new topic:
[[%SCRIPTURLPATH{"edit"}%/%WEB%/BugIDXXXXXXXXXX?templatetopic=BugTemplate&amp;topicparent=%TOPIC%&amp;t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]=

Master Templates by Example

Attached is an example of an oops based template oopsbase.tmpl and an example oops dialog oopstest.tmpl based on the base template. TIP NOTE: This isn't the release version, just a quick, simple demo.

 

Base template oopsbase.tmpl

Line: 189 to 226
 <html> <head> <title> %WIKITOOLNAME% . %WEB% . %TOPIC% %.TMPL:P{"titleaction"}%</title>
Changed:
<
<
<base href="%SCRIPTURL%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%">
>
>
<base href="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%">
  <meta name="robots" content="noindex"> </head> <body bgcolor="#FFFFFF">
Line: 266 to 303
 
testscreen.gif
Changed:
<
<

Known Issues

  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
>
>
Related Topics: TWikiSkins, DeveloperDocumentationCategory, AdminDocumentationCategory
 
Changed:
<
<
-- TWiki:Main.CrawfordCurrie - 30 Jun 2004
-- TWiki:Main.PeterThoeny - 15 Aug 2004
-- TWiki:Main.MikeMannix - 14 Sep 2001
-- TWiki:Main.DavidLeBlanc - 11 Mar 2002
>
>
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="TWikiContributor" version="1.2"
 
Deleted:
<
<
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 232004-08-15 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 59 to 59
 

HTML Page Templates

Changed:
<
<
URCS uses HTML template files for 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.
>
>
TWiki uses HTML template files for 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.
 
Changed:
<
<
Templates are in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script. Templates can be overloaded by individual webs. The following search order applies:
>
>
Templates are stored either in the twiki/templates directory or in user topics. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script.
 
Changed:
<
<
  1. twiki/templates/$webName/$scriptName.tmpl
  2. twiki/templates/$scriptName.tmpl
    • $webName is the name of the web (ex: Main)
    • $scriptName is the script (ex: view).
>
>
HELP Templates can be overloaded by individual webs.
 
Changed:
<
<
HELP NOTE: TWikiSkins can be defined to overload the standard templates.
>
>
HELP TWikiSkins can overload the standard templates.

TWiki uses the following search order to determine which template to use:

If a skin is specified If no skin is specified
templates/%WEB%/script.skin.tmpl templates/%WEB%/script.tmpl
templates/script.skin.tmpl templates/script.tmpl
data/%WEB%/SkinSkinScriptTemplate.txt data/%WEB%/ScriptTemplate.txt
data/TWiki/SkinSkinScriptTemplate.txt data/TWiki/ScriptTemplate.txt
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
skin refers to the skin name, e.g dragon, pattern
Skin refers to the same, but with the first character capitalized, e.g Dragon
%WEB% refers to the current web

Additionally (and primarily for use in %TMPL:INCLUDE{}%) the template name may be a wiki topic name, specified as Web.Topic, in which case the search is:

If a skin is specified If no skin is specified
templates/web/Web.Topic.skin.tmpl templates/web/Web.Topic.tmpl
templates/Web.Topic.skin.tmpl templates/Web.Topic.tmpl
data/Web/Topic.txt
If Web is not specified in the INCLUDE, it defaults to TWiki, and the search to the first type.
  Special variables are used in templates, especially in view, to display meta data.
Line: 149 to 166
 
templatetopic The name of the template topic, e.g. topic used to copy the initial content
topicparent Sets the parent topic
TopicClassification Assuming the template topic has a form with a field called "TopicClassification", it will set the value of the field
Added:
>
>
contenttype Optional parameter that defines the application type to write into the CGI header. Defaults to text/html. May be used to invoke alternative client applications
 
anyname Any parameter can passed to the new topic; if the template topic contains %URLPARAM{"anyname"}%, it will be replaced by its value
Line: 252 to 270
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
Changed:
<
<
-- TWiki:Main.PeterThoeny - 25 Apr 2004
>
>
-- TWiki:Main.CrawfordCurrie - 30 Jun 2004
-- TWiki:Main.PeterThoeny - 15 Aug 2004
 -- TWiki:Main.MikeMannix - 14 Sep 2001
-- TWiki:Main.DavidLeBlanc - 11 Mar 2002

Revision 222004-04-25 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 95 to 95
 
Variable: Description:
%DATE% Current date, e.g. 2018-11-18
Changed:
<
<
%WIKIUSERNAME% User name, e.g. Main.TWikiGuest
>
>
%USERNAME% Login name, e.g. jsmith
%WIKINAME% WikiName of user, e.g. JohnSmith
%WIKIUSERNAME% User name, e.g. Main.JohnSmith
 
%URLPARAM{"name"}% Value of a named URL parameter
%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 text that gets removed. Useful to write-protect an edit template topic, but not the topics based this template topic. See notes below. Example:
%NOP{
   * Set ALLOWTOPICCHANGE = Main.TWikiAdminGroup
  }%
Line: 250 to 252
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
Changed:
<
<
-- TWiki:Main.PeterThoeny - 30 Dec 2004
>
>
-- TWiki:Main.PeterThoeny - 25 Apr 2004
 -- TWiki:Main.MikeMannix - 14 Sep 2001
-- TWiki:Main.DavidLeBlanc - 11 Mar 2002
Added:
>
>
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 212003-12-31 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 117 to 117
 
Added:
>
>
  (date format is YYYYxMMxDD)
Line: 130 to 131
  <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> <input type="hidden" name="topicparent" value="%TOPIC%" /> <input type="hidden" name="onlywikiname" value="on" />
Added:
>
>
<input type="hidden" name="onlynewtopic" value="on" />
  <input type="submit" value="Create" /> (date format is <nop>YYYYxMMxDD) </form>
Line: 141 to 143
 
Parameter: Description:
topic Name of topic to create. Can be set in a text field, or is set programmatically (e.g. with a sequential number)
onlywikiname If set, TWiki will complain if the topic name is not a WikiWord
Added:
>
>
onlynewtopic If set, TWiki will complain if a topic of the same name already exists
 
templatetopic The name of the template topic, e.g. topic used to copy the initial content
topicparent Sets the parent topic
TopicClassification Assuming the template topic has a form with a field called "TopicClassification", it will set the value of the field
Line: 247 to 250
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
Changed:
<
<
-- TWiki:Main.PeterThoeny - 16 Dec 2003
>
>
-- TWiki:Main.PeterThoeny - 30 Dec 2004
 -- TWiki:Main.MikeMannix - 14 Sep 2001
-- TWiki:Main.DavidLeBlanc - 11 Mar 2002
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"

Revision 202003-12-16 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 135 to 135
 </form>
Changed:
<
<
The onlywikiname parameter enforces WikiWords for topic names. The topicparent parameter sets the topic parent to the topic where the form is located.
>
>
The edit scipt understands the following parameters, typically supplied by HTML input fields:

Parameter: Description:
topic Name of topic to create. Can be set in a text field, or is set programmatically (e.g. with a sequential number)
onlywikiname If set, TWiki will complain if the topic name is not a WikiWord
templatetopic The name of the template topic, e.g. topic used to copy the initial content
topicparent Sets the parent topic
TopicClassification Assuming the template topic has a form with a field called "TopicClassification", it will set the value of the field
anyname Any parameter can passed to the new topic; if the template topic contains %URLPARAM{"anyname"}%, it will be replaced by its value
  TIP 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%
Line: 237 to 247
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
Changed:
<
<
-- PeterThoeny - 01 Feb 2003
-- MikeMannix - 14 Sep 2001
-- TWiki:Main/DavidLeBlanc - 11 Mar 2002
>
>
-- TWiki:Main.PeterThoeny - 16 Dec 2003
-- TWiki:Main.MikeMannix - 14 Sep 2001
-- TWiki:Main.DavidLeBlanc - 11 Mar 2002
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 192003-04-02 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 115 to 115
 
  • New example topic:
Added:
>
>
  (date format is YYYYxMMxDD)
Line: 126 to 128
 
  • New example topic: <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />
Added:
>
>
<input type="hidden" name="topicparent" value="%TOPIC%" />
  <input type="hidden" name="onlywikiname" value="on" /> <input type="submit" value="Create" /> (date format is <nop>YYYYxMMxDD) </form>
Changed:
<
<
The onlywikiname parameter enforces WikiWords for topic names.
>
>
The onlywikiname parameter enforces WikiWords for topic names. The topicparent parameter sets the topic parent to the topic where the form is located.
  TIP 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%

Revision 182003-02-01 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 88 to 88
 
  1. WebTopicEditTemplate in the current web
  2. WebTopicEditTemplate in the TWiki web
Added:
>
>

Edit Template Topics and Variable Expansion

The following variables get expanded when a user creates a new topic based on a template topic:

Variable: Description:
%DATE% Current date, e.g. 2018-11-18
%WIKIUSERNAME% User name, e.g. Main.TWikiGuest
%URLPARAM{"name"}% Value of a named URL parameter
%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 text that gets removed. Useful to write-protect an edit template topic, but not the topics based this template topic. See notes below. Example:
%NOP{
   * Set ALLOWTOPICCHANGE = Main.TWikiAdminGroup
  }%

Notes:

  • Unlike other variables, %NOP{ ... }% can span multiple lines.
  • The scan for the closing }% pattern is "non-greedy", that is, it stops at the first occurance. That means, you need to escape variables with parameters located inside %NOP{ ... }%: Insert a %NOP% between } and %. Silly example: %NOP{ %GMTIME{"$year"}%NOP%% }%.

All other variables are unchanged, e.g. are carried over "as is" into the new topic.

 

Template Topics in Action

Here is an example for creating new topics based on a specific template topic:

Line: 215 to 234
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
Changed:
<
<
-- PeterThoeny - 23 Jul 2001
>
>
-- PeterThoeny - 01 Feb 2003
 -- MikeMannix - 14 Sep 2001
-- TWiki:Main/DavidLeBlanc - 11 Mar 2002
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"

Revision 172003-01-08 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 92 to 92
  Here is an example for creating new topics based on a specific template topic:
Changed:
<
<
>
>
 
  • New example topic:
Line: 103 to 103
 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:


Changed:
<
<
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%URLENCODE{"%WEB%"}%/">
>
>
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%"}%/">
 
  • New example topic: <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />

Revision 162003-01-05 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 92 to 92
  Here is an example for creating new topics based on a specific template topic:
Changed:
<
<
>
>
 
  • New example topic:
Line: 103 to 103
 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:


Changed:
<
<
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEBURLENCODED%/">
>
>
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%URLENCODE{"%WEB%"}%/">
 
  • New example topic: <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />

Revision 152003-01-05 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 92 to 92
  Here is an example for creating new topics based on a specific template topic:
Changed:
<
<
>
>
 
  • New example topic:
Line: 103 to 103
 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:


Changed:
<
<
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/">
>
>
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEBURLENCODED%/">
 
  • New example topic: <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />

Revision 142003-01-04 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 18 to 18
 
  • defines common variables, like a standard separator (ex: "|"), in the base template;
  • defines variable text in the individual templates and passes it back to the base template.
Added:
>
>
 

How Template Variables Work

  • Special template directives (or preprocessor commands) are embedded in normal templates.

Revision 132002-12-20 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 8 to 8
 

Overview

Changed:
<
<
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML mark-up for template-specific content. Templates are used to define page layout, and also to supplydefault content for new pages.
>
>
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML markup for template-specific content. Templates are used to define page layout, and also to supply default content for new pages.
 

Major changes from the previous template system

Line: 18 to 18
 
  • defines common variables, like a standard separator (ex: "|"), in the base template;
  • defines variable text in the individual templates and passes it back to the base template.
Changed:
<
<

Functional Specifications

>
>

How Template Variables Work

 
  • Special template directives (or preprocessor commands) are embedded in normal templates.
Deleted:
<
<
  • Use of template directives is optional, templates work without them.
 
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before).
Changed:
<
<
  • Directives are of the form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
>
>
  • Directives are of the form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
 
  • Directives:
Changed:
<
<
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The template directory of the current web is searched first, then the templates root (twiki/templates).
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
  • Variables are live in a global name space, there is no parameter passing.
  • Two-pass processing, so that you can use a variable before declaring it or after.
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
  • NOTE: The template directives work only for templates, they do not get processed in topic text.
>
>
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The template directory of the current web is searched first, then the templates root (twiki/templates).
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
  • Variables live in a global name space: there is no parameter passing.
  • Two-pass processing lets you use a variable before or after declaring it.
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads only the twiki.tmpl master template, like twiki.print.tmpl, that redefines the header and footer.
  • HELP Use of template directives is optional: templates work without them.
  • ALERT! NOTE: Template directives work only for templates: they do not get processed in topic text.
 
Changed:
<
<

TWiki Master Template

>
>

Types of Template

There are three types of template:

  • Master Template: Stores common parts; included by other templates
  • HTML Page Templates: Defines the layout of URCS pages
  • Template Topics: Defines default text when you create a new topic

Master Templates

 
Changed:
<
<
All common parts are defined in a master template, twiki.tmpl, that all other templates use.
>
>
Common parts, appearing in two or more templates, can be defined in a master template and then shared by others: twiki.tmpl is the default master template.
 
Template variable: Defines:
%TMPL:DEF{"sep"}% "|" separator
%TMPL:DEF{"htmldoctype"}% Start of all HTML pages
Changed:
<
<
%TMPL:DEF{"standardheader"}% Standard header (ex: view, index, seach)
>
>
%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
Deleted:
<
<

Types of Template

There are two types of templates:

  • HTML Page Templates: Defines layout of URCS pages
  • Template Topics: Defines default text when you create a new topic
 

HTML Page Templates

Changed:
<
<
URCS uses HTML template files for all actions like topic view, edit, preview and so on. This allows you to change the look and feel of all pages by editing just some template files.
>
>
URCS uses HTML template files for 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.
 
Changed:
<
<
The template files are in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script. Templates can be overloaded per web. The following search order applies:
>
>
Templates are in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script. Templates can be overloaded by individual webs. The following search order applies:
 
  1. twiki/templates/$webName/$scriptName.tmpl
  2. twiki/templates/$scriptName.tmpl
Added:
>
>
    • $webName is the name of the web (ex: Main)
    • $scriptName is the script (ex: view).
 
Changed:
<
<
Note: $webName is the name of the web (ex: Main), and $scriptName is the script (ex: view).

Note: TWikiSkins can be defined to overload the standard templates.

>
>
HELP NOTE: TWikiSkins can be defined to overload the standard templates.
  Special variables are used in templates, especially in view, to display meta data.

Template Topics

Changed:
<
<
Template topics define the default text for new topics. There are three types of template topics:
>
>
Template topics define the default text for new topics. There are three types of template topic:
 
Topic Name: What it is:
Changed:
<
<
WebTopicViewTemplate Help text shown when you view a non existing topic.
WebTopicNonWikiTemplate Help text shown when you view a non existing topic that has not a WikiName.
>
>
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.
Changed:
<
<
All template topics are located in the TWiki web. The WebTopicEditTemplate can be overloaded. The following search order applies when you create a new topic:
>
>
All template topics are located in the TWiki web. The WebTopicEditTemplate can be overloaded. When you create a new topic, TWiki locates a topic to use as a content template according to the following search order:
 
Changed:
<
<
  1. The topic name specified by the templatetopic CGI parameter.
  2. WebTopicEditTemplate in the current web.
  3. WebTopicEditTemplate in the TWiki web.
>
>
  1. A topic name specified by the templatetopic CGI parameter.
  2. WebTopicEditTemplate in the current web
  3. WebTopicEditTemplate in the TWiki web
 

Template Topics in Action

Line: 98 to 99
  (date format is YYYYxMMxDD)
Changed:
<
<
Above form asks for a topic name. A hidden input tag of name "templatetopic" specifies the ExampleTopicTemplate as the template topic. Here is the HTML source of the form:
>
>
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:
 
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/">

Line: 111 to 112
 </form>
Changed:
<
<
The "onlywikiname" parameter enforces WikiWords for topic names.
>
>
The onlywikiname parameter enforces WikiWords for topic names.
 
Changed:
<
<
Note: Use can use the %WIKIUSERNAME% and %DATE% variables in your topic templates as the signature; those variables are expanded when a new topic is created. The standard topic signature is:
-- %WIKIUSERNAME% - %DATE%
>
>
TIP 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%
 

Templates by Example

Changed:
<
<
Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. NOTE: This isn't the release version, just a quick, simple demo.
>
>
Attached is an example of an oops based template oopsbase.tmpl and an example oops dialog oopstest.tmpl based on the base template. %A% NOTE: This isn't the release version, just a quick, simple demo.
 

Base template oopsbase.tmpl

Changed:
<
<
The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%
>
>
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"}%
 
Line: 205 to 207
 With URL: .../bin/oops/Sandbox/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify

Changed:
<
<
testscreen.gif
>
>
testscreen.gif
 

Known Issues

Changed:
<
<
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template is a structurally complete HTML document with a .tmpl filename extension - it contains unresolved %VARIABLES%, but can still be previewed directly in a browser.
>
>
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template was a structurally complete HTML document with a .tmpl filename extension - it contained unresolved %VARIABLES%, but could still be previewed directly in a browser.
  -- PeterThoeny - 23 Jul 2001
-- MikeMannix - 14 Sep 2001
Added:
>
>
-- TWiki:Main/DavidLeBlanc - 11 Mar 2002
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 122002-07-18 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 202 to 202
 

Sample screen shot of oopstest.tmpl

Changed:
<
<
With URL: .../bin/oops/Test/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify
>
>
With URL: .../bin/oops/Sandbox/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify
 
Changed:
<
<
testscreen.gif
>
>
testscreen.gif
 

Known Issues

Line: 214 to 214
  -- PeterThoeny - 23 Jul 2001
-- MikeMannix - 14 Sep 2001
Changed:
<
<
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"
>
>
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="1026977240" name="testscreen.gif" path="C:\Data\Temp\testscreen.gif" size="9566" user="PeterThoeny" version="1.2"
 
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 102001-09-18 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 8 to 8
 

Overview

Changed:
<
<
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML mark-up for template-specific content.
>
>
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML mark-up for template-specific content. Templates are used to define page layout, and also to supplydefault content for new pages.
 

Major changes from the previous template system

Line: 54 to 54
 
  • HTML Page Templates: Defines layout of URCS pages
  • Template Topics: Defines default text when you create a new topic
Added:
>
>
 

HTML Page Templates

URCS uses HTML template files for all actions like topic view, edit, preview and so on. This allows you to change the look and feel of all pages by editing just some template files.

Line: 69 to 70
  Special variables are used in templates, especially in view, to display meta data.
Added:
>
>
 

Template Topics

Template topics define the default text for new topics. There are three types of template topics:

Revision 92001-09-16 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Changed:
<
<

TWiki Template System

>
>

TWiki Templates

  Definition of the templates used to render all HTML pages displayed in TWiki

Overview

Changed:
<
<
The new modular template system is more flexible, efficient, and easily updated than the old set-up, where each template is a complete HTML file. The new master template approach places common templates parts, like headers and footers, in one shared file. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for TWikiSkins.
>
>
The new modular template system offers flexible, easy control over the layout of all TWiki pages. The master template approach groups parts that are shared by several templates - like headers and footers - in a common file. Special variables allow individual layouts to include parts from a master template - variables are mixed with regular HTML mark-up for template-specific content.
 

Major changes from the previous template system

Changed:
<
<
The main difference is that templates are now defined using variables to include template parts. You change one stored instance of a common element to update all occurrences. The new system:
>
>
Where the old templates were each complete HTML documents, the new templates are defined using variables to include template parts from a master file. You can now change one instance of a common element to update all occurrences; previously, every affected template had to be updated. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for TWikiSkins. The new system:
 
  • separates a set of common template parts into a base template that is included by all of the related templates;
Deleted:
<
<
 
  • defines common variables, like a standard separator (ex: "|"), in the base template;
Deleted:
<
<
 
  • defines variable text in the individual templates and passes it back to the base template.

Functional Specifications

Line: 34 to 32
 
  • Variables are live in a global name space, there is no parameter passing.
  • Two-pass processing, so that you can use a variable before declaring it or after.
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
Changed:
<
<
  • Note: The template directives work only for templates, they do not get processed in topic text.
>
>
  • NOTE: The template directives work only for templates, they do not get processed in topic text.
 

TWiki Master Template

Revision 82001-09-15 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 48 to 48
 
%TMPL:DEF{"standardfooter"}% Footer, excluding revision and copyright parts
%TMPL:DEF{"oops"}% Skeleton of oops dialog
Added:
>
>
 

Types of Template

Added:
>
>
 There are two types of templates:

  • HTML Page Templates: Defines layout of URCS pages
Line: 80 to 82
  All template topics are located in the TWiki web. The WebTopicEditTemplate can be overloaded. The following search order applies when you create a new topic:
Changed:
<
<
  1. The topic name specified by the templatetopic parameter.
>
>
  1. The topic name specified by the templatetopic CGI parameter.
 
  1. WebTopicEditTemplate in the current web.
  2. WebTopicEditTemplate in the TWiki web.
Line: 90 to 92
 
  • New example topic:
Changed:
<
<
(date format is YYYYMMDD)
>
>
(date format is YYYYxMMxDD)
 

Above form asks for a topic name. A hidden input tag of name "templatetopic" specifies the ExampleTopicTemplate as the template topic. Here is the HTML source of the form:

Line: 100 to 103
 
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/">
	* New example topic: 

Changed:
<
<
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$year$mo$day}%" size="22"> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate"> <input type="hidden" name="onlywikiname" value="on"> <input type="submit" value="Create"> (date format is YYYYMMDD)
>
>
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" /> <input type="hidden" name="templatetopic" value="ExampleTopicTemplate" /> <input type="hidden" name="onlywikiname" value="on" /> <input type="submit" value="Create" /> (date format is <nop>YYYYxMMxDD)
 </form>

Revision 72001-09-15 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 63 to 63
 
  1. twiki/templates/$webName/$scriptName.tmpl
  2. twiki/templates/$scriptName.tmpl
Changed:
<
<
Note: $webName is the name of the web ( i.e. Main ), and $scriptName is the script ( i.e. view ).
>
>
Note: $webName is the name of the web (ex: Main), and $scriptName is the script (ex: view).
  Note: TWikiSkins can be defined to overload the standard templates.
Changed:
<
<
Some special variables are used in templates ( especially view ) to show meta data - see Meta Data Rendering
>
>
Special variables are used in templates, especially in view, to display meta data.
 

Template Topics

Revision 62001-09-15 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 36 to 36
 
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
  • Note: The template directives work only for templates, they do not get processed in topic text.
Changed:
<
<

New Template System by Example

>
>

TWiki Master Template

All common parts are defined in a master template, twiki.tmpl, that all other templates use.

Template variable: Defines:
%TMPL:DEF{"sep"}% "|" separator
%TMPL:DEF{"htmldoctype"}% Start of all HTML pages
%TMPL:DEF{"standardheader"}% Standard header (ex: view, index, seach)
%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

Types of Template

There are two types of templates:

  • HTML Page Templates: Defines layout of URCS pages
  • Template Topics: Defines default text when you create a new topic

HTML Page Templates

URCS uses HTML template files for all actions like topic view, edit, preview and so on. This allows you to change the look and feel of all pages by editing just some template files.

The template files are in the twiki/templates directory. As an example, twiki/templates/view.tmpl is the template file for the twiki/bin/view script. Templates can be overloaded per web. The following search order applies:

  1. twiki/templates/$webName/$scriptName.tmpl
  2. twiki/templates/$scriptName.tmpl

Note: $webName is the name of the web ( i.e. Main ), and $scriptName is the script ( i.e. view ).

Note: TWikiSkins can be defined to overload the standard templates.

Some special variables are used in templates ( especially view ) to show meta data - see Meta Data Rendering

Template Topics

Template topics define the default text for new topics. There are three types of template topics:

Topic Name: What it is:
WebTopicViewTemplate Help text shown when you view a non existing topic.
WebTopicNonWikiTemplate Help text shown when you view a non existing topic that has not a WikiName.
WebTopicEditTemplate Default text shown when you create a new topic.
All template topics are located in the TWiki web. The WebTopicEditTemplate can be overloaded. The following search order applies when you create a new topic:

  1. The topic name specified by the templatetopic parameter.
  2. WebTopicEditTemplate in the current web.
  3. WebTopicEditTemplate in the TWiki web.

Template Topics in Action

Here is an example for creating new topics based on a specific template topic:

  • New example topic: (date format is YYYYMMDD)

Above form asks for a topic name. A hidden input tag of name "templatetopic" specifies the ExampleTopicTemplate as the template topic. Here is the HTML source of the form:

<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/">
	* New example topic: 
	  <input type="text" name="topic" value="ExampleTopic%SERVERTIME{$year$mo$day}%" size="22">
	  <input type="hidden" name="templatetopic" value="ExampleTopicTemplate">
	  <input type="hidden" name="onlywikiname" value="on">
	  <input type="submit" value="Create"> (date format is YYYYMMDD)
</form>

The "onlywikiname" parameter enforces WikiWords for topic names.

Note: Use can use the %WIKIUSERNAME% and %DATE% variables in your topic templates as the signature; those variables are expanded when a new topic is created. The standard topic signature is:
-- %WIKIUSERNAME% - %DATE%

Templates by Example

  Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. NOTE: This isn't the release version, just a quick, simple demo.
Line: 44 to 119
  The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%
Changed:
<
<
>
>
 
%TMPL:DEF{"sep"}% | %TMPL:END%

Line: 90 to 165
 
Deleted:
<
<
 

Test template oopstest.tmpl

Each oops template basically just defines some variables and includes the base template that does the layout work.

Changed:
<
<
>
>
 
%TMPL:DEF{"titleaction"}% (test =titleaction=) %TMPL:END%

Line: 126 to 200
  With URL: .../bin/oops/Test/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify
Changed:
<
<
>
>
 
testscreen.gif
Deleted:
<
<

TWiki master template

All common template parts are defined in one master template, twiki.tmpl, that all other templates include.

Template variable: Defines:
%TMPL:DEF{"sep"}% "|" separator
%TMPL:DEF{"htmldoctype"}% Start of all HTML pages
%TMPL:DEF{"standardheader"}% Standard header (ex: view, index, seach)
%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

Example: oopspreview.tmpl template
%TMPL:INCLUDE{"twiki"}%
%TMPL:DEF{"titleaction"}% (oops) %TMPL:END%
%TMPL:DEF{"webaction"}% *Attention* %TMPL:END%
%TMPL:DEF{"heading"}% Topic is not saved yet %TMPL:END%
%TMPL:DEF{"message"}% Please go back in your browser and save the topic. %TMPL:END%
%TMPL:DEF{"topicaction"}%
%TMPL:END%
%TMPL:P{"oops"}%
 

Known Issues

  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template is a structurally complete HTML document with a .tmpl filename extension - it contains unresolved %VARIABLES%, but can still be previewed directly in a browser.
Changed:
<
<
-- PeterThoeny - 23 Jul 2001
-- MikeMannix - 30 Aug 2001
>
>
-- PeterThoeny - 23 Jul 2001
-- MikeMannix - 14 Sep 2001
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 52001-09-14 - PeterThoeny

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 8 to 8
 

Overview

Changed:
<
<
The new modular template system is more flexible, efficient, and easily updated than the old set-up, where each template is a complete HTML file. The new master template approach places common templates parts, like headers and footers, in one shared file. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for skins.
>
>
The new modular template system is more flexible, efficient, and easily updated than the old set-up, where each template is a complete HTML file. The new master template approach places common templates parts, like headers and footers, in one shared file. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for TWikiSkins.
 

Major changes from the previous template system

Line: 26 to 26
 
  • Use of template directives is optional, templates work without them.
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before).
  • Directives are of the form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
Changed:
<
<
  • Initial set of directives:
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The usual search path is applied.
>
>
  • Directives:
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The template directory of the current web is searched first, then the templates root (twiki/templates).
 
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
Deleted:
<
<
  • New directives can be added over time when needed, ex: IF-THEN-ELSE.
 
  • Variables are live in a global name space, there is no parameter passing.
  • Two-pass processing, so that you can use a variable before declaring it or after.
Changed:
<
<
  • Templates and skins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
>
>
  • Templates and TWikiSkins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
 
  • Note: The template directives work only for templates, they do not get processed in topic text.

New Template System by Example

Line: 45 to 44
  The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%
Deleted:
<
<
NOTE: Added a dot to escape rendering of variables, i.e. read %.WEB% as %WEB%.
 
Added:
>
>
 

Changed:
<
<
<table border="1" cellspacing="0" cellpadding="1"> <tr><td> <verbatim> %.TMPL:DEF{"sep"}% | %.TMPL:END%
>
>
%TMPL:DEF{"sep"}% | %TMPL:END%
 <html> <head>
Changed:
<
<
<title> %.WIKITOOLNAME% . %.WEB% . %.TOPIC% %.TMPL:P{"titleaction"}%</title> <base href="%.SCRIPTURL%/view%.SCRIPTSUFFIX%/%.WEB%/%.TOPIC%">
>
>
<title> %WIKITOOLNAME% . %WEB% . %TOPIC% %.TMPL:P{"titleaction"}%</title> <base href="%SCRIPTURL%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%">
  <meta name="robots" content="noindex"> </head> <body bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="3" cellspacing="0"> <tr>
Changed:
<
<
<td bgcolor="%.WEBBGCOLOR%" rowspan="2" valign="top" width="1%"> <a href="%.WIKIHOMEURL%"> <img src="%.PUBURLPATH%/wikiHome.gif" border="0"></a>
>
>
<td bgcolor="%WEBBGCOLOR%" rowspan="2" valign="top" width="1%"> <a href="%WIKIHOMEURL%"> <img src="%PUBURLPATH%/wikiHome.gif" border="0"></a>
  </td> <td>
Changed:
<
<
<b>%.WIKITOOLNAME% . %.WEB% . </b><font size="+2"> <B>%.TOPIC%</b> %.TMPL:P{"titleaction"}%</font>
>
>
<b>%WIKITOOLNAME% . %WEB% . </b><font size="+2"> <B>%TOPIC%</b> %TMPL:P{"titleaction"}%</font>
  </td> </tr>
Changed:
<
<
<tr bgcolor="%.WEBBGCOLOR%">
>
>
<tr bgcolor="%WEBBGCOLOR%">
  <td colspan="2">
Changed:
<
<
%.TMPL:P{"webaction"}%
>
>
%TMPL:P{"webaction"}%
  </td> </tr> </table>
Changed:
<
<

++ %.TMPL:P{"heading"}% %.TMPL:P{"message"}%
>
>

++ %TMPL:P{"heading"}% %TMPL:P{"message"}%
 <table width="100%" border="0" cellpadding="3" cellspacing="0">
Changed:
<
<
<tr bgcolor="%.WEBBGCOLOR%">
>
>
<tr bgcolor="%WEBBGCOLOR%">
  <td valign="top">
Changed:
<
<
Topic <b>TWikiTemplates</b> . { %.TMPL:P{"topicaction"}%
>
>
Topic <b>%TOPIC%</b> . { %TMPL:P{"topicaction"}%
  } </td> </tr> </table> </body>
Deleted:
<
<
</verbatim> </td></tr> </table >
 
Added:
>
>
 
Line: 103 to 98
 
Changed:
<
<
%.TMPL:DEF{"titleaction"}% (test =titleaction=) %.TMPL:END%
%.TMPL:DEF{"webaction"}% test =webaction= %.TMPL:END%
%.TMPL:DEF{"heading"}%
Test heading %.TMPL:END%
%.TMPL:DEF{"message"}%
>
>
%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...
Changed:
<
<
  • Param1: %PARAM1%
  • Param2: %PARAM2%
  • Param3: %PARAM3%
  • Param4: %PARAM4%
%.TMPL:END% %.TMPL:DEF{"topicaction"}%
>
>
  • Param1: %PARAM1%
  • Param2: %PARAM2%
  • Param3: %PARAM3%
  • Param4: %PARAM4%
%TMPL:END% %TMPL:DEF{"topicaction"}%
 Test topicaction:
Changed:
<
<
OK %.TMPL:P{"sep"}% Register %.TMPL:END% %.TMPL:INCLUDE{"oopsbase"}%
>
>
[[%WEB%.%TOPIC%][OK]] %TMPL:P{"sep"}% [[%TWIKIWEB%.TWikiRegistration][Register]] %TMPL:END% %TMPL:INCLUDE{"oopsbase"}%
  </table >
Line: 135 to 130
 
testscreen.gif
Added:
>
>

TWiki master template

 All common template parts are defined in one master template, twiki.tmpl, that all other templates include.

Template variable: Defines:
Line: 146 to 143
 
%TMPL:DEF{"oops"}% Skeleton of oops dialog

Changed:
<
<
Example: preview.tmpl template
>
>
Example: oopspreview.tmpl template
 
%TMPL:INCLUDE{"twiki"}%
%TMPL:DEF{"titleaction"}% (oops) %TMPL:END%

Line: 163 to 160
 
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template is a structurally complete HTML document with a .tmpl filename extension - it contains unresolved %VARIABLES%, but can still be previewed directly in a browser.
Changed:
<
<
-- PeterThoeny - 23 Jul 2001
>
>
-- PeterThoeny - 23 Jul 2001
 -- MikeMannix - 30 Aug 2001
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 42001-09-12 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Line: 166 to 166
 -- PeterThoeny - 23 Jul 2001
-- MikeMannix - 30 Aug 2001
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"
Added:
>
>
META TOPICMOVED by="MikeMannix" date="1000277381" from="TWiki.TWikiTemplateSystem" to="TWiki.TWikiTemplates"

Revision 32001-09-08 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Deleted:
<
<

new topic for the final doc

Slightly edited down, but waiting for new docs, hopefully.

see also for ref: orig TWikiTemplatingSystem

 
Deleted:
<
<
 

TWiki Template System

Changed:
<
<
Define the templates used to render all HTML pages displayed in TWiki
>
>
Definition of the templates used to render all HTML pages displayed in TWiki
 
Changed:
<
<

Overview

>
>

Overview

 
Changed:
<
<
We have a need for more advanced template handling. As JohnTalintyre pointed out in CommonHeaderFooterTemplate it makes sense to separate the header and footer into one file so that it can be easily altered (or even overloaded by a skin). Also the oops dialog messages are all identical except for a few variables like heading, and so on.
>
>
The new modular template system is more flexible, efficient, and easily updated than the old set-up, where each template is a complete HTML file. The new master template approach places common templates parts, like headers and footers, in one shared file. This simplifies the conversion of templates into XHTML format, and provides a more versatile solution for templates and for skins.
 
Changed:
<
<
Using external modules like the TemplateToolkit would be one way to go, but this will add a lot of baggage to TWiki.
>
>

Major changes from the previous template system

 
Changed:
<
<

Needs of the TWiki templating system

>
>
The main difference is that templates are now defined using variables to include template parts. You change one stored instance of a common element to update all occurrences. The new system:
 
Changed:
<
<
  • Separate common parts into one (or more) base template file(s) and include that from other template files like view.tmpl.
  • Define common variables like a "|" separator in the base template and use them in other template files
  • Define variable text in templates (i.e. view.tmpl) and pass them to the base template
>
>
  • separates a set of common template parts into a base template that is included by all of the related templates;
 
Changed:
<
<

Functional Spec

>
>
  • defines common variables, like a standard separator (ex: "|"), in the base template;
 
Changed:
<
<
I tried to define a simple but powerful solution that can be extended over time. Here we go:
>
>
  • defines variable text in the individual templates and passes it back to the base template.

Functional Specifications

 
  • Special template directives (or preprocessor commands) are embedded in normal templates.
  • Use of template directives is optional, templates work without them.
Changed:
<
<
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before)
  • Directives are of form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
>
>
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before).
  • Directives are of the form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
 
  • Initial set of directives:
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The usual search path is applied.
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
Changed:
<
<
  • New directives can be added over time when needed, i.e. IF-THEN-ELSE.
  • Variables live in a global name space, there is no parameter passing.
  • Two pass processing, so that you can use a variable before declaring it or after.
  • Templates and skins work transparently and interchangeably. You could for example define a new skin just for the header & footer and keep the other template files unchanged.
  • Note: The template directive work only for templates, they do not get processed in topic text.
>
>
  • New directives can be added over time when needed, ex: IF-THEN-ELSE.
  • Variables are live in a global name space, there is no parameter passing.
  • Two-pass processing, so that you can use a variable before declaring it or after.
  • Templates and skins work transparently and interchangeably. For example, you can create a skin that overloads just the twiki.tmpl, like twiki.print.tmpl, that redefines the header and footer.
  • Note: The template directives work only for templates, they do not get processed in topic text.
 
Changed:
<
<

Examples

>
>

New Template System by Example

 
Changed:
<
<
Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. This is not the version that will go into the release, it is just a quick hack.
>
>
Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. NOTE: This isn't the release version, just a quick, simple demo.
 
Changed:
<
<

Base template oopsbase.tmpl

>
>

Base template oopsbase.tmpl

  The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%
Changed:
<
<
Note: Added a dot to escape rendering of variables, i.e. read %.WEB% as %WEB%.
>
>
NOTE: Added a dot to escape rendering of variables, i.e. read %.WEB% as %WEB%.
 
Added:
>
>
 
<table border="1" cellspacing="0" cellpadding="1">
<tr><td>

Line: 99 to 93
 </td></tr> </table >
Added:
>
>
 
Changed:
<
<

Test template oopstest.tmpl

>
>

Test template oopstest.tmpl

  Each oops template basically just defines some variables and includes the base template that does the layout work.
Added:
>
>
 
Line: 129 to 125
  </table >
Added:
>
>
 
Changed:
<
<

Sample screen shot of oopstest.tmpl

>
>

Sample screen shot of oopstest.tmpl

  With URL: .../bin/oops/Test/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify
Added:
>
>
 
testscreen.gif
Added:
>
>
 
Changed:
<
<

Comments and feedback

  • The itching factor to put this into the upcoming release is to easy the pending converstion of the templates into XHTML format and to have a more flexible solution for templates and skins.
  • Is the terminology OK?
  • Is the spec OK?
  • Are there any other directives that are needed urgently?
  • One drawback by using the directives is that you can only test a template from within TWiki. This is because you don't have a text that has a linear flow when you use TMPL:DEF, TMPL:P and TMPL:INCLUDE.

-- PeterThoeny - 21 Jul 2001

  • It's probably more readable to enforce variables being defined before use, which would avoid need for slower two-pass processing.
    • [ PeterThoeny ] You need two-pass processing because you need to define the "|" separator in the included template onone side, and on the other side define variables for the included template. The processing happens as regex in memory, so there is no mesurable speed penalty.
  • It would be nice to simplify the syntax a bit, e.g. not using "" around variable names (they don't really need it, unlike filenames), and not using braces - however, this is not a big deal and there is some merit in keeping consistent with the current TWiki syntax.
    • [ PeterThoeny ] The templating system uses the standard internal TWiki function to parse variable attributes. The "" can be skipped (is possible but is not documented).

Please have a look at the latest templates in the TWikiAlphaRelease. There is now one master template called twiki.tmpl that all other templates include (well, will include when all done). The idea is to define all common parts of the templates in twiki.tmpl and simply use that from all other templates.

>
>
All common template parts are defined in one master template, twiki.tmpl, that all other templates include.
 
Template variable: Defines:
Changed:
<
<
%TMPL:DEF{"sep"}% %TMPL:END% "|" separator
>
>
%TMPL:DEF{"sep"}% "|" separator
 
%TMPL:DEF{"htmldoctype"}% Start of all HTML pages
Changed:
<
<
%TMPL:DEF{"standardheader"}% Standard header (for view, rdiff, ...
%TMPL:DEF{"simpleheader"}% Simple header with reduced links (for edit, attach, oops,...)
%TMPL:DEF{"standardfooter"}% Footer, excluding revision part and copyright part
>
>
%TMPL:DEF{"standardheader"}% Standard header (ex: view, index, seach)
%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
Changed:
<
<
I.e. the preview.tmpl template is now simply:
>
>
Example: preview.tmpl template
 
%TMPL:INCLUDE{"twiki"}%
%TMPL:DEF{"titleaction"}% (oops) %TMPL:END%
%TMPL:DEF{"webaction"}% *Attention* %TMPL:END%
%TMPL:DEF{"heading"}% Topic is not saved yet %TMPL:END%

Changed:
<
<
%TMPL:DEF{"message"}% Please go back in your browser and save the topic. %TMPL:END% %TMPL:DEF{"topicaction"}% %TMPL:END%
>
>
%TMPL:DEF{"message"}% Please go back in your browser and save the topic. %TMPL:END% %TMPL:DEF{"topicaction"}% %TMPL:END%
 %TMPL:P{"oops"}%
Added:
>
>

Known Issues

 
Changed:
<
<
With this it should be possible to create a skin that overloads just the twiki.tmpl, i.e. a twiki.print.tmpl that redefines the header and footer.
>
>
  • A drawback of referring to a master template is that you can only test a template from within TWiki, where the include variables are resolved. In the previous system, each template is a structurally complete HTML document with a .tmpl filename extension - it contains unresolved %VARIABLES%, but can still be previewed directly in a browser.
  -- PeterThoeny - 23 Jul 2001
-- MikeMannix - 30 Aug 2001
Deleted:
<
<
 
META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"

Revision 22001-09-07 - MikeMannix

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

new topic for the final doc

Line: 8 to 8
 
Changed:
<
<

TWiki Template System

>
>

TWiki Template System

  Define the templates used to render all HTML pages displayed in TWiki
Changed:
<
<

Overview

>
>

Overview

  We have a need for more advanced template handling. As JohnTalintyre pointed out in CommonHeaderFooterTemplate it makes sense to separate the header and footer into one file so that it can be easily altered (or even overloaded by a skin). Also the oops dialog messages are all identical except for a few variables like heading, and so on.

Using external modules like the TemplateToolkit would be one way to go, but this will add a lot of baggage to TWiki.

Changed:
<
<

Needs of the TWiki templating system

>
>

Needs of the TWiki templating system

 
  • Separate common parts into one (or more) base template file(s) and include that from other template files like view.tmpl.
  • Define common variables like a "|" separator in the base template and use them in other template files
  • Define variable text in templates (i.e. view.tmpl) and pass them to the base template
Changed:
<
<

Functional Spec

>
>

Functional Spec

  I tried to define a simple but powerful solution that can be extended over time. Here we go:
Line: 44 to 44
 
  • Note: The template directive work only for templates, they do not get processed in topic text.
Changed:
<
<

Examples

>
>

Examples

  Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. This is not the version that will go into the release, it is just a quick hack.
Changed:
<
<
Base template oopsbase.tmpl
>
>

Base template oopsbase.tmpl

  The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%
Line: 101 to 101
 
Changed:
<
<
Test template oopstest.tmpl
>
>

Test template oopstest.tmpl

  Each oops template basically just defines some variables and includes the base template that does the layout work.
Line: 130 to 130
  </table >
Changed:
<
<
Sample screen shot of oopstest.tmpl
>
>

Sample screen shot of oopstest.tmpl

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

testscreen.gif
Changed:
<
<

Comments and feedback

>
>

Comments and feedback

 
  • The itching factor to put this into the upcoming release is to easy the pending converstion of the templates into XHTML format and to have a more flexible solution for templates and skins.
  • Is the terminology OK?

Revision 12001-09-04 - MikeMannix

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WebHome"

new topic for the final doc

Slightly edited down, but waiting for new docs, hopefully.

see also for ref: orig TWikiTemplatingSystem

TWiki Template System

Define the templates used to render all HTML pages displayed in TWiki

Overview

We have a need for more advanced template handling. As JohnTalintyre pointed out in CommonHeaderFooterTemplate it makes sense to separate the header and footer into one file so that it can be easily altered (or even overloaded by a skin). Also the oops dialog messages are all identical except for a few variables like heading, and so on.

Using external modules like the TemplateToolkit would be one way to go, but this will add a lot of baggage to TWiki.

Needs of the TWiki templating system

  • Separate common parts into one (or more) base template file(s) and include that from other template files like view.tmpl.
  • Define common variables like a "|" separator in the base template and use them in other template files
  • Define variable text in templates (i.e. view.tmpl) and pass them to the base template

Functional Spec

I tried to define a simple but powerful solution that can be extended over time. Here we go:

  • Special template directives (or preprocessor commands) are embedded in normal templates.
  • Use of template directives is optional, templates work without them.
  • All template preprocessing is done in &TWiki::Store::readTemplate() so that the caller simply gets an expanded template file (the same as before)
  • Directives are of form %TMPL:<key>% and %TMPL:<key>{"attr"}%.
  • Initial set of directives:
    • %TMPL:INCLUDE{"file"}%: Includes a template file. The usual search path is applied.
    • %TMPL:DEF{"var"}%: Define a variable. Text between this and the END directive is not returned, but put into a hash for later use.
    • %TMPL:END%: Ends variable definition.
    • %TMPL:P{"var"}%: Prints a previously defined variable.
  • New directives can be added over time when needed, i.e. IF-THEN-ELSE.
  • Variables live in a global name space, there is no parameter passing.
  • Two pass processing, so that you can use a variable before declaring it or after.
  • Templates and skins work transparently and interchangeably. You could for example define a new skin just for the header & footer and keep the other template files unchanged.
  • Note: The template directive work only for templates, they do not get processed in topic text.

Examples

Attached is an example of an oops base template oopsbase.tmpl and a example oops dialog oopstest.tmpl which is based on the base template. This is not the version that will go into the release, it is just a quick hack.

Base template oopsbase.tmpl

The first line declares the delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing %TMPL:P{"sep"}%

Note: Added a dot to escape rendering of variables, i.e. read %.WEB% as %WEB%.

<table border="1" cellspacing="0" cellpadding="1">
<tr><td>
<verbatim>
%.TMPL:DEF{"sep"}% | %.TMPL:END%
<html>
<head>
  <title> %.WIKITOOLNAME% . %.WEB% . %.TOPIC% %.TMPL:P{"titleaction"}%</title>
  <base href="%.SCRIPTURL%/view%.SCRIPTSUFFIX%/%.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>TWikiTemplates</b> . {
		  %.TMPL:P{"topicaction"}%
		}
	 </td>
  </tr>
</table>
</body>
</verbatim>
</td></tr>
</table >

Test template oopstest.tmpl

Each oops template basically just defines some variables and includes the base template that does the layout work.

</table >

Sample screen shot of oopstest.tmpl

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

%.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"}%
testscreen.gif

Comments and feedback

  • The itching factor to put this into the upcoming release is to easy the pending converstion of the templates into XHTML format and to have a more flexible solution for templates and skins.
  • Is the terminology OK?
  • Is the spec OK?
  • Are there any other directives that are needed urgently?
  • One drawback by using the directives is that you can only test a template from within TWiki. This is because you don't have a text that has a linear flow when you use TMPL:DEF, TMPL:P and TMPL:INCLUDE.

-- PeterThoeny - 21 Jul 2001

  • It's probably more readable to enforce variables being defined before use, which would avoid need for slower two-pass processing.
    • [ PeterThoeny ] You need two-pass processing because you need to define the "|" separator in the included template onone side, and on the other side define variables for the included template. The processing happens as regex in memory, so there is no mesurable speed penalty.
  • It would be nice to simplify the syntax a bit, e.g. not using "" around variable names (they don't really need it, unlike filenames), and not using braces - however, this is not a big deal and there is some merit in keeping consistent with the current TWiki syntax.
    • [ PeterThoeny ] The templating system uses the standard internal TWiki function to parse variable attributes. The "" can be skipped (is possible but is not documented).

Please have a look at the latest templates in the TWikiAlphaRelease. There is now one master template called twiki.tmpl that all other templates include (well, will include when all done). The idea is to define all common parts of the templates in twiki.tmpl and simply use that from all other templates.

Template variable: Defines:
%TMPL:DEF{"sep"}% %TMPL:END% "|" separator
%TMPL:DEF{"htmldoctype"}% Start of all HTML pages
%TMPL:DEF{"standardheader"}% Standard header (for view, rdiff, ...
%TMPL:DEF{"simpleheader"}% Simple header with reduced links (for edit, attach, oops,...)
%TMPL:DEF{"standardfooter"}% Footer, excluding revision part and copyright part
%TMPL:DEF{"oops"}% Skeleton of oops dialog

I.e. the preview.tmpl template is now simply:

%TMPL:INCLUDE{"twiki"}%
%TMPL:DEF{"titleaction"}% (oops) %TMPL:END%
%TMPL:DEF{"webaction"}% *Attention* %TMPL:END%
%TMPL:DEF{"heading"}% Topic is not saved yet %TMPL:END%
%TMPL:DEF{"message"}%
  Please go back in your browser and save the topic. %TMPL:END%
%TMPL:DEF{"topicaction"}% %TMPL:END%
%TMPL:P{"oops"}%

With this it should be possible to create a skin that overloads just the twiki.tmpl, i.e. a twiki.print.tmpl that redefines the header and footer.

-- PeterThoeny - 23 Jul 2001
-- MikeMannix - 30 Aug 2001

META FILEATTACHMENT attr="h" comment="Example of oopstest.tmpl rendered" date="999598142" name="testscreen.gif" path="C:\02_TWikiDocs\testscreen.gif" size="9460" user="MikeMannix" version="1.1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TWikiTemplates.