Templates

Description

The current implementation of templates allows you to create a set of pages in the template category that can be used as initial content for newly created pages. The problem is that there is no real binding between the template and the page and once a page is saved - it is completely independent from the template.

In large wikis with dozens of pages created from such defined templates there is no easy way to change the layout for pages that were created with a given template

Therefore we would like to introduce "live templates". Such template would consist of a special template definition (located in category-name:_template, one template per category) and would influence the way that pages are rendered and viewed.

Details

Template pages would be a type of a "special page" (name starts with an underscore) within categories. Examples of template definition pages would be:

_template
category:_template
bugs:_template
proposals:_template

Special pages, starting with the underscore, would not be listed by other modules and hidden in most cases.

Defining layout

The purpose of a template is to define a layout of pages within a category. An example will explain everything:

+ Original content of the page below

%%content%%

----------------

[[module Comments]]

It is easy to image what it really does. When this markup is saved as some-category:_template, all pages from the some-category will be combined with the template during rendering. Content of the page will be substituted into the %%content%% tag. This way we can add headers, side bars, navigation elements, modules and comment boxes to the template and the viewed page will automatically have it.

When you try editing a page from the category, only the "inside content" is editable. Template is applied only when viewing the compiled page.

Splitting the content.

Let us start with an example of a template:

[[div style="float:right; width: 200px; border: 1px solid #999; margin: 10px;"]]
%%content{1}%%
[[/div]]

%%content{2}%%

[[table]]
[[row]]
[[column]]
%%content{3}%%
[[/column]]
[[column]]
%%content{4}%%
[[/column]]
[[/row]]
[[/table]]

==== 

This will be content of the side bar.

==== 

The main content.

==== 

This will go into the left cell of the table.

==== 

And this into the right cell.

There are two things described above: splitting content and default page content.

Splitting allows you to create sections in the page and manipulate them separately in the template. Sections are separated by a series (4 or more) "equals" characters and are referred to as %%content{X}%% in the template. You can access them in any order within the template.

Using this you can easily create advanced layouts (like multicolumn, multi-navigation etc.) and make editing and maintenance much easier.

Default content

Also in the template you can provide the default initial content for newly created pages. Such content is separated from the template by the '====' tag - the same as for splitting the content. To make it visually different you can make it longer — e.g. 10 characters. When a user wants to start a new page in the category, this content will be placed in the editor.

Also, when default content is defined for the template, there will be no option for selecting templates from the templates category (our previous templating mechanism).

Escaping the ==== tag

Since you might want to use the "====" tag in the content of a page and NOT as a splitter, there is a way to escape the splitter and prevent the default action. Simply append a space character to the end of the tag, before you hit enter.

==== 
    ^ extra space before newline

Changing the template

When you edit the _template page for the given category, all pages from the category will be recompiled to include the changed template.


Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License