Line: 1 to 1 | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Deleted: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
On this page:
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:
| ||||||||||||||||||||
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: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > | 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
| ||||||||||||||||||||
> > | How Template Directives Work
| ||||||||||||||||||||
| |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > |
| ||||||||||||||||||||
| |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > |
| ||||||||||||||||||||
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: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > | 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 TemplatesTemplates are stored either in thetwiki/templates directory, or can also be read from user topics. As an example, twiki/templates/view.tmpl is the default template file for the twiki/bin/view script.
Templates that are included using %TMPL:INCLUDE% are also found using the same search algorithm, unless you explicitly put '.tmpl' at the end of the template name. In this case, the string is assumed to be the full name of a template in the templates directory, and the algorithm isn't used.
TWiki uses the following search order to determine which template file or topic to use for a particular script. The skin path is set as described in TWikiSkins. | ||||||||||||||||||||
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. | ||||||||||||||||||||
> > | For example, the example template file will be searched for in the following places, when the current web is Thisweb and the skin path is print,pattern :
view and edit scripts, for example when a topic-specific template is required. Two preference variables can be user to override the templates used:
view and edit respectively. The template search order is as specified above.
Master TemplatesMaster templates use the block definition directives (%TMPL:DEF and %TMPL:END% ) to define common sections that appear in two or more other templates. twiki.tmpl is the default master template. | ||||||||||||||||||||
| |||||||||||||||||||||
Line: 57 to 108 | |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < | HTML Page TemplatesTWiki 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 thetwiki/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: | |||||||||||||||||||||
< < | ![]() | ||||||||||||||||||||
> > | 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: | |||||||||||||||||||||
< < | ![]() | ||||||||||||||||||||
> > | 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:
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 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 | |||||||||||||||||||||
| |||||||||||||||||||||
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: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > |
| ||||||||||||||||||||
| |||||||||||||||||||||
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:
| |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > |
| ||||||||||||||||||||
| |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < |
| ||||||||||||||||||||
> > |
| ||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < | Notes:
| ||||||||||||||||||||
> > | %STARTSECTION{type="templateonly"}% markers are used to embed text that you do not want expanded when a new topic based on the template topic is created. For example, you might want to write in the template topic:
%STARTSECTION{type="templateonly"}% This template can only be changed by: * Set ALLOWTOPICCHANGE = %MAINWEB%.TWikiAdminGroup %ENDSECTION{type="templateonly"}%This will restrict who can edit the template topic, but will get removed when a new topic based on that template topic is created. %NOP% can be used to prevent expansion of TWiki variables that would otherwise be expanded during topic creation e.g.i escape %nop>SERVERTIME% with %SER%NOP%VERTIME% . | ||||||||||||||||||||
All other variables are unchanged, e.g. are carried over "as is" into the new topic. | |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < | Template Topics in Action | ||||||||||||||||||||
> > | Template Topics in Action | ||||||||||||||||||||
Here is an example for creating new topics based on a specific template topic: | |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < | |||||||||||||||||||||
> > | |||||||||||||||||||||
| |||||||||||||||||||||
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%/"> | ||||||||||||||||||||
| |||||||||||||||||||||
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:
| ||||||||||||||||||||
> > | See TWikiScripts for details of the parameters that the edit script understands. | ||||||||||||||||||||
![]() %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 TopicnameIf you want to make a TWiki application where you need automatically generated unique topicnames, you can use 10 X's in the edit / save URL, and they will be replaced on topic save with a count value. For example, BugIDXXXXXXXXXX will result in topics named BugID0, BugID1, BugID2 etc. | ||||||||||||||||||||
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&topicparent=%TOPIC%&t=%SERVERTIME{"$day$hour$min$sec"}%][Create new item]]= Master Templates by ExampleAttached is an example of an oops based templateoopsbase.tmpl and an example oops dialog oopstest.tmpl based on the base template. ![]() | ||||||||||||||||||||
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 | |||||||||||||||||||||
| |||||||||||||||||||||
Changed: | |||||||||||||||||||||
< < | Known Issues
| ||||||||||||||||||||
> > | 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 | ||||||||||||||||||||
> > |
| ||||||||||||||||||||
Deleted: | |||||||||||||||||||||
< < |
|