-# <a name="new topic for the final doc"></a> new topic for the final doc
-
-Slightly edited down, but waiting for new docs, hopefully.
-
-see also for ref: orig [[TWikiTemplatingSystem]]
-
<div>
<ul>
- <li><a href="#new topic for the final doc"> new topic for the final doc</a></li>
- <li><a href="#TWiki Template System"> TWiki Template System</a></li>
- <li><a href="#Overview"> Overview</a><ul>
- <li><a href="#Needs of the TWiki templating sy"> Needs of the TWiki templating system</a></li>
- <li><a href="#Functional Spec"> Functional Spec</a></li>
- <li><a href="#Examples"> Examples</a><ul>
- <li>
- <ul>
- <li><a href="#Base template oopsbase.tmpl"> Base template oopsbase.tmpl</a></li>
- <li><a href="#Test template oopstest.tmpl"> Test template oopstest.tmpl</a></li>
- <li><a href="#Sample screen shot of oopstest.t"> Sample screen shot of oopstest.tmpl</a></li>
+ <li><a href="#TWiki Template System"> TWiki Template System</a><ul>
+ <li><a href="#Overview"> Overview</a></li>
+ <li><a href="#Major changes from the previous"> Major changes from the previous template system</a></li>
+ <li><a href="#Functional Specifications"> Functional Specifications</a></li>
+ <li><a href="#TWiki Master Template"> TWiki Master Template</a></li>
+ <li><a href="#Types of Template"> Types of Template</a><ul>
+ <li><a href="#HTML Page Templates"> HTML Page Templates</a></li>
+ <li><a href="#Template Topics"> Template Topics</a><ul>
+ <li><a href="#Template Topics in Action"> Template Topics in Action</a></li>
</ul>
</li>
</ul>
</li>
- <li><a href="#Comments and feedback"> Comments and feedback</a></li>
+ <li><a href="#Templates by Example"> Templates by Example</a><ul>
+ <li><a href="#Base template oopsbase.tmpl"> Base template oopsbase.tmpl</a></li>
+ <li><a href="#Test template oopstest.tmpl"> Test template oopstest.tmpl</a></li>
+ <li><a href="#Sample screen shot of oopstest.t"> Sample screen shot of oopstest.tmpl</a></li>
+ </ul>
+ </li>
+ <li><a href="#Known Issues"> Known Issues</a></li>
</ul>
</li>
</ul>
# <a name="TWiki Template System"></a> TWiki Template System
-_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_
+
+## <a name="Overview"></a> Overview
-# <a name="Overview"></a> Overview
+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]].
-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.
+## <a name="Major changes from the previous"></a><a name="Major changes from the previous "></a> Major changes from the previous template system
-Using external modules like the [[TemplateToolkit]] would be one way to go, but this will add a lot of baggage to TWiki.
+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:
-## <a name="Needs of the TWiki templating sy"></a> Needs of the TWiki templating system
+- separates a set of common template parts into a base template that is included by all of the related templates;
-- 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
+- defines common variables, like a standard separator (ex: "|"), in the base template;
-## <a name="Functional Spec"></a> Functional Spec
+- defines variable text in the individual templates and passes it back to the base template.
-I tried to define a simple but powerful solution that can be extended over time. Here we go:
+## <a name="Functional Specifications"></a> Functional Specifications
- 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.
+- 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"}%`.
+- 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.
-- 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.
+- 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.
+
+## <a name="TWiki Master Template"></a> TWiki Master Template
+
+All common parts are defined in a master template, <code>**twiki.tmpl**</code>, that all other templates use.
+
+> <table border="1" cellpadding="0" cellspacing="0">
+> <tr>
+> <th bgcolor="#99CCCC"><strong> Template variable: </strong></th>
+> <th bgcolor="#99CCCC"><strong> Defines: </strong></th>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"sep"}% </td>
+> <td> "|" separator </td>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"htmldoctype"}% </td>
+> <td> Start of all HTML pages </td>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"standardheader"}% </td>
+> <td> Standard header (ex: view, index, seach) </td>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"simpleheader"}% </td>
+> <td> Simple header with reduced links (ex: edit, attach, oops) </td>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"standardfooter"}% </td>
+> <td> Footer, excluding revision and copyright parts </td>
+> </tr>
+> <tr>
+> <td> %TMPL:DEF{"oops"}% </td>
+> <td> Skeleton of oops dialog </td>
+> </tr>
+> </table>
+
+## <a name="Types of Template"></a> Types of Template
+
+There are two types of templates:
+
+- **HTML Page Templates**: Defines layout of %WIKITOOLNAME% pages
+- **Template Topics**: Defines default text when you create a new topic
+
+### <a name="HTML Page Templates"></a> HTML Page Templates
+
+%WIKITOOLNAME% 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 <code>**twiki/templates**</code> directory. As an example, <code>**twiki/templates/view.tmpl**</code> is the template file for the <code>**twiki/bin/view**</code> script. Templates can be overloaded per web. The following search order applies:
+
+1. <code>**twiki/templates/$webName/$scriptName.tmpl**</code>
+2. <code>**twiki/templates/$scriptName.tmpl**</code>
+
+**_Note:_** `$webName` is the name of the web (ex: `Main`), and <code>**$scriptName**</code> is the script (ex: `view`).
+
+**_Note:_** [[TWikiSkins]] can be defined to overload the standard templates.
+
+Special variables are used in templates, especially in `view`, to display [[meta data|Main/TWikiMetaData#MetaDataRendering]].
+
+### <a name="Template Topics"></a> Template Topics
+
+Template topics define the default text for new topics. There are three types of template topics:
+
+> <table border="1" cellpadding="0" cellspacing="0">
+> <tr>
+> <th bgcolor="#99CCCC"><strong> Topic Name: </strong></th>
+> <th bgcolor="#99CCCC"><strong> What it is: </strong></th>
+> </tr>
+> <tr>
+> <td>[[Main/WebTopicViewTemplate]]</td>
+> <td> Help text shown when you view a non existing topic. </td>
+> </tr>
+> <tr>
+> <td>[[Main/WebTopicNonWikiTemplate]]</td>
+> <td> Help text shown when you view a non existing topic that has not a [[Main/WikiName]]. </td>
+> </tr>
+> <tr>
+> <td>[[Main/WebTopicEditTemplate]]</td>
+> <td> Default text shown when you create a new topic. </td>
+> </tr>
+> </table>
+
+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:
-## <a name="Examples"></a> Examples
+1. The topic name specified by the `templatetopic` CGI parameter.
+2. WebTopicEditTemplate in the current web.
+3. WebTopicEditTemplate in the TWiki web.
-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.
+#### <a name="Template Topics in Action"></a> Template Topics in Action
-#### <a name="Base template oopsbase.tmpl"></a> Base template oopsbase.tmpl
+Here is an example for creating new topics based on a specific template topic:
+
+<form action="http://www.dementia.org/twiki//edit/%WEB%/" name="new">
+ <ul>
+ <li> New example topic: <input name="topic" size="23" type="text" value="ExampleTopic2010x06x29" /> <input name="templatetopic" type="hidden" value="ExampleTopicTemplate" /> <input type="submit" value="Create" /> (date format is YYYYxMMxDD) </li>
+ </ul>
+</form>
+
+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{$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>
+
+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: <br />`-- %WIKIUSERNAME% - %DATE%`
+
+## <a name="Templates by Example"></a> 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.
+
+### <a name="Base template oopsbase.tmpl"></a> 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 <code>**%.WEB%**</code> as <code>**%WEB%**</code>.
-
- <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>%TOPIC%</b> . {
- %.TMPL:P{"topicaction"}%
- }
- </td>
- </tr>
- </table>
- </body>
- </verbatim>
- </td></tr>
- </table >
-
-#### <a name="Test template oopstest.tmpl"></a> Test template oopstest.tmpl
+> <table bgcolor="#f5f5f5" border="1" cellpadding="1" cellspacing="0">
+> <tr>
+> <td><pre>
+> %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>%TOPIC%</b> . {
+> %TMPL:P{"topicaction"}%
+> }
+> </td>
+> </tr>
+> </table>
+> </body>
+> </pre></td>
+> </tr>
+> </table>
+
+### <a name="Test template oopstest.tmpl"></a> Test template oopstest.tmpl
Each oops template basically just defines some variables and includes the base template that does the layout work.
-<table border="1" cellpadding="1" cellspacing="0">
- <tr>
- <td><pre>
-%.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"}%
-</pre></td>
- </tr>
- <tr>
- <td> </table > <p>
- </p>
- <h4><a name="Sample screen shot of oopstest.t"></a> Sample screen shot of oopstest.tmpl </h4>
- <p> With URL: <code><b>.../bin/oops/Test/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify</b></code></p>
- <p>
- </p>
- <table border="1" cellpadding="0" cellspacing="0">
- <tr>
- <td><img alt="testscreen.gif" height="304" src="http://www.dementia.org/twiki//view/testscreen.gif" width="554" /></td>
- </tr>
- </table>
- <p>
- </p>
- <h2><a name="Comments and feedback"></a> Comments and feedback </h2>
- <p>
- </p>
- <ul>
- <li> 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. </li>
- <li> Is the terminology OK? </li>
- <li> Is the spec OK? </li>
- <li> Are there any other directives that are needed urgently? </li>
- <li> 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. </li>
- </ul>
- <p> -- [[Main/PeterThoeny]] - 21 Jul 2001 <br />
- </p>
- <p>
- </p>
- <ul>
- <li> It's probably more readable to enforce variables being defined before use, which would avoid need for slower two-pass processing. <ul>
- <li> [ [[Main/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. </li>
- </ul>
- </li>
- <li> 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. <ul>
- <li> [ [[Main/PeterThoeny]] ] The templating system uses the standard internal TWiki function to parse variable attributes. The "" can be skipped (is possible but is not documented). </li>
- </ul>
- </li>
- </ul>
- <p>
- </p>
- <p> Please have a look at the latest templates in the [[Main/TWikiAlphaRelease]]. There is now one master template called <code>twiki.tmpl</code> that all other templates include (well, will include when all done). The idea is to define all common parts of the templates in <code>twiki.tmpl</code> and simply use that from all other templates. </p>
- <p>
- </p>
- <table border="1" cellpadding="0" cellspacing="0">
- <tr>
- <th bgcolor="#99CCCC"><strong> Template variable: </strong></th>
- <th bgcolor="#99CCCC"><strong> Defines: </strong></th>
- </tr>
- <tr>
- <td> %TMPL:DEF{"sep"}% </td>
- <td> %TMPL:END% </td>
- <td> "|" separator </td>
- </tr>
- <tr>
- <td> %TMPL:DEF{"htmldoctype"}% </td>
- <td> Start of all HTML pages </td>
- </tr>
- <tr>
- <td> %TMPL:DEF{"standardheader"}% </td>
- <td> Standard header (for view, rdiff, ... </td>
- </tr>
- <tr>
- <td> %TMPL:DEF{"simpleheader"}% </td>
- <td> Simple header with reduced links (for edit, attach, oops,...) </td>
- </tr>
- <tr>
- <td> %TMPL:DEF{"standardfooter"}% </td>
- <td> Footer, excluding revision part and copyright part </td>
- </tr>
- <tr>
- <td> %TMPL:DEF{"oops"}% </td>
- <td> Skeleton of oops dialog </td>
- </tr>
- </table>
- <p> I.e. the <code>preview.tmpl</code> template is now simply: </p><pre>
-%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"}%
-</pre><p> With this it should be possible to create a skin that overloads just the <code>twiki.tmpl</code>, i.e. a <code>twiki.print.tmpl</code> that redefines the header and footer. </p>
- <p> -- [[Main/PeterThoeny]] - 23 Jul 2001 <br /> -- [[Main/MikeMannix]] - 30 Aug 2001 </p>
- <p>
- </p>
- </td>
- </tr>
-</table>
+> <table bgcolor="#f5f5f5" border="1" cellpadding="1" cellspacing="0">
+> <tr>
+> <td><pre>
+> %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"}%
+> </pre></td>
+> </tr>
+> <tr>
+> <td> </table > </td>
+> </tr>
+> </table>
+
+### <a name="Sample screen shot of oopstest.t"></a> Sample screen shot of oopstest.tmpl
+
+With URL: <code>**.../bin/oops/Test/TestTopic2?template=oopstest&param1=WebHome&param2=WebNotify**</code>
+
+> <table border="1" cellpadding="0" cellspacing="0">
+> <tr>
+> <td><img alt="testscreen.gif" height="304" src="http://www.dementia.org/twiki//view/testscreen.gif" width="554" /></td>
+> </tr>
+> </table>
+
+## <a name="Known Issues"></a> 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.
+
+-- [[PeterThoeny]] - 23 Jul 2001 <br /> -- [[MikeMannix]] - 14 Sep 2001 <br />