Templating System Usage

To use a template, start by adding ",new" after almost any URL on our site to see the templates available at that point of the site. ",new" is one of the comma-tools.

The text below explains how to create templates.

A few things to know to create a template

The templating system helps you create uniform documents for W3C pages, or helps you to prepare documents for particular circumstances (Last Call, etc).

New templates must be created in a directory which is called Templates.

General usage

The description and the title

It is recommended to add a very short description of the template in a meta tag at the top of the document, e.g.:

<meta name="description" content="Press release">

The ,new tool will otherwise display the title of the document, but often the title is just "%%title%%".

%%variable-name%%

When the template is called, a form will be created and displayed with the value of variable-name to input. We suggest that you choose a variable name which has a meaning. Spaces are allowed, but no colons (:) or equals signs (=). For example:

%%Your email address%%

The form will contain an entry with "Your email address" and an input field.

%%variable-name=default-value%%

Same as above, but the form will show an input field pre-filled with the given default value.

%%url-escape: variable-name%%

This is for the rare case of variables that are inserted into a URL. E.g., if the template contains:

... <a href="http://example.org/process?name=%%name%%">process it...

and the variable "name" happens to contain certain characters such as "&", "=" or "/", the link will be incorrect. Instead, write it like this:

... <a href="http://example.org/process?name=%%url-escape:name">process it...

Don't use it where the variable constitutes the whole of the URL, such as in <a href="%%url%%">

Technically, the prefix "url-escape" instructs the templating system to use so-called "%-escapes".

%%variable-name:option,option,option%%

Instead of an input field for text, the form will contain a menu with the given options.

Do not put spaces after the colon (:) or after the commas (,), unless you want an actual space in the value.

%%variable-name:option,option,option=default%%

Same as above, but the option that is equal to the default is already selected (instead of the first option). E.g.,

... %%color:red,green,blue,purple=blue%%...

will show a menu that looks like this:

URL-escaping, menus and defaults can be combined. E.g., here is a variable that has a menu of options, with a default option, and that will be URL-escaped in the generated document:

... %%url-escape: fraction:1/2,1/3,1/4,1/5=1/3%%..
%%yyyy%%

When the variable is exactly yyyy, the form will show an input field prefilled with the current year. For example, "1969"

%%mm%%

The form will show an input field prefilled with the month as two digits. For example, "02" for February

%%mmm%%

The form wil show an input field prefilled with the month in a 3-letter format. For example, "Feb" for February

%%dd%%

The form will show an input field prefilled with the date. For example, "16"

%%if: variable-name%% … %%else%% … %%endif: variable-name%%
%%if: variable-name%% … %%endif: variable-name%%

It is possible to make conditional sections in a template. The part after %%if:variable-name%% will only be copied to the output if variable-name is defined (has a non-empty value). Otherwise, if there is an %%else%%, the part after %%else%% will be copied.

Somes examples of templates.


Valid XHTML 1.0!
Created Date: 2003-08-14 by Karl Dubost
Last modified $Date: 2021/11/09 00:00:05 $ by $Author: bbos $

Copyright © 2000-2003 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply. Your interactions with this site are in accordance with our public and Member privacy statements.