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:
| ||||||||||||
> > | 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:
| ||||||||||||
![]() | |||||||||||||
Changed: | |||||||||||||
< < | The TWiki Template System | ||||||||||||
> > |
Master TemplatesTWiki 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: | |||||||||||||
< < |
| ||||||||||||
| |||||||||||||
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: | |||||||||||||
< < | |||||||||||||
| |||||||||||||
Line: 69 to 75 | |||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
Legend:
| |||||||||||||
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: | |||||||||||||
> > | |||||||||||||
| |||||||||||||
Line: 88 to 95 | |||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
| ||||||||||||
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: | ||||||||||||
| |||||||||||||
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 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.
| ||||||||||||
> > | 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 templatetwiki.tmpl is the default master template. It defines the following sections. | ||||||||||||
| |||||||||||||
Deleted: | |||||||||||||
< < |
HTML Page TemplatesHTML page templates are files of HTML mixed with template directives that tell TWiki how to build up an HTML page. As described above, the template system supports the use of 'include' directives that let you re-use the same sections of HTML - such as headers and footers - in several different places. TWiki uses HTML page templates when composing the output from all actions, like topic view, edit, and preview. This allows you to change the look and feel of all pages by editing just a few template files. HTML page templates are also used in the definition of TWikiSkins. | ||||||||||||
Template 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: | ||||||||||||
| |||||||||||||
Changed: | |||||||||||||
< < |
| ||||||||||||
> > |
edit script, TWiki locates a topic to use as a content template according to the following search order:
| ||||||||||||
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: | |||||||||||||
< < | |||||||||||||
| |||||||||||||
Line: 163 to 160 | |||||||||||||
| |||||||||||||
Deleted: | |||||||||||||
< < | |||||||||||||
%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: | |||||||||||||
Changed: | |||||||||||||
< < | %STARTSECTION{type="templateonly"}% | ||||||||||||
> > | %STARTSECTION{type="templateonly"}% | ||||||||||||
This template can only be changed by: | |||||||||||||
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. | |||||||||||||
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 FormWhen 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 theformtemplate 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 NamesFor TWiki applications it is useful to be able to automatically generate unique topicnames, such as BugID0001, BugID0002, etc. You can addAUTOINC<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:
[[%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: | |||||||||||||
< < | |||||||||||||
> > | |||||||||||||
| |||||||||||||
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/"> | ||||||||||||
| |||||||||||||
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 | |||||||||||||
![]() %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 TopicnameFor TWiki application it is useful to automatically generate unique topicnames, such as BugID0001, BugID0002, etc. You can addAUTOINC<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:
[[%SCRIPTURLPATH{"edit"}%/%WEB%/BugIDAUTOINC00000?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.tmplThe first line declares a delimiter variable called "sep", used to separate multiple link items. The variable can be called anywhere by writing%TMPL:P{"sep"}%
%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.tmplEach 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.tmplWith URL:.../bin/oops/Sandbox/TestTopic2?template=oopstest¶m1=WebHome¶m2=WebNotify
![]() | ||||||||||||
> > | 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
| ||||||||||||
> > | -- Contributors: TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.DavidLeBlanc, TWiki:Main.CrawfordCurrie |