Summary
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 surround the splitter with "@@" like below:
@@====@@
Page variables within the _template (new!!!)
With the growing popularity of the ListPages module and increasing use of its formatting tags (like %%title%%) we have introduced some formatting variables to the template pages. The supported tags are:
| variable | aliases | description |
|---|---|---|
| %%title%% | title of the page | |
| %%linked_title%% | %%title_linked%% | title of the page linked to the page itself |
| %%page_unix_name%% | unix name of the page — the one that is displayed in the URL of a page | |
| %%category%% | name of the category of the page | |
| %%link%% | URL pointing to the page | |
| %%author%% | prints author that created page | |
| %%date%% | prints the date the page was created | |
| %%date|format%% | prints date with a custom format. Most tokens from php's strftime are accepted. You may find the howto contributed by community useful. | |
| %%date_edited%% | prints the date the page was recently edited | |
| %%date_edited|format%% | same as above, with custom formatting | |
| %%rating%% | displays a number — rating of the page | |
| %%comments%% | displays number of comments to the page |
An example of how these can be used in a blog could be (e.g. in blog:_template:
by %%author%% on %%date|%e %B %Y%%
rating: %%rating%%, tags: %%tags%%
%%content%%
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.
Note: templating system is originally described on our dev site.
Comments
Has anyone already implemented this? I would like to see it working…
http://community.wikidot.com/help:template
Brunhilda - I used live templates on my site - http://ubuntu.wieza.org - the footer (comments, edit and print and icons) are added this way.
Look at: http://ubuntu.wieza.org/software:pdfedit
And to compare: http://ubuntu.wieza.org/software:_template
I didn't use sections for now.
What would a page editor see if editing a page based on a split up template? Do they only get to edit one section at a time, or is there something which makes it clear what section is what?
To give an example, I want to use a template which determines that every page has a standard set of headings. Clearly the headings would be in the template. If the user doesn't see these headings when editing, how do they know which section their text will appear in.
(I'm sure this would be clear with some experimentation, but time is a bit tight and I'm sure others will want to know the answer)
Useful for newbies like me, who start by creating pages without using categories at all:
1.- You create five pages in your wiki. Later you realize that there are categories and templates, so you want to use some categories and a different template for each category. So this is what you do. First, check the list of your initial files:
page1
page2
page3
page4
page5
2.- In order to create two categories ("literature" and "music") and to classify your files in categories, rename the files:
literature:page1
literature:page2
literature:page3
music:page4
music:page5
3.- When you have a bunch of pages within a category, if you create a template, all pages within the category automatically will use the template. For instance, if you create:
literature:_template
Then "literature:page1", "literature:page2" and "literature:page3" will use the new template.
I'd love to see variables like %%author%%, %%date%%, %%page_unix_name%% and %%linked_title%%, included in the Default content area of a template, that would substitute for their respective values when the page is published. It would save a nice a chunk of repetitive typing and time.
Example template
Actually, I'm quite new to these stuffs. It would be great if there are some simpler definitions for templates as well as examples how it was applied. I may understand what the functions of these codes shown are; however, it would be easier if someone can put some pictures describing how the page will be after applied these codes. Thank you !
I absolutely agree with fortunzfavor… if we had access to more variables then these live templates would be an even more powerful thing!
OK,
I created a page and called it Template_Library.
I started the page with
_template
followed by the template text I wanted the template to hold, and saved it.
Then I went to create a new page.
The template is not auto loaded and there is no popup offering me a list of templates to choose from.
How do I use templates when I make a new page?
Also, I don't know if it is relevant - I put the Comments module code onto the bottom of my home page and now get the warning
Module comments does not exist or can not be used within this site.
So far, not very impressed - it all seems a bit developmental and perhaps not ready for public consumption yet.
For example, there seems not to be any auto-notification option for posting comments ??
DerekSmith
This works great! Thanks for implementing it.
One comment… I'd like the option to have specific pages within the category "opt out" of the template.
I think, actually, that the best way to implement the live template is with the use of the old-fashioned template as well (but I've only had my wikidot for a day, so what do I know?).
Basically I've created a book category which has a few headings and some standard things I want each page to have.
My book:_template (the live template) page, basically looks like this.
And then I've got template:book (the old sort of template)
and used the site manager to link it to everything in the book category.
So now, whenever I want to create a page, I know what goes where, and can even remember to keep the ====s there.
Hope that helps you.
@mandraco
Just put the sections at the bottom of the _template with the default content, and it will appear on any new page.
I just discovered that, actually. I should have known there was an easier way. =)
Can you bypass the live template if you want a category page in a different style to it (e.g. for a category front page)
Edit: well, i guess you could just make a regular page (not in the category) and link it to the appropriate place in the category…but then it wouldn't be automatically in category listings etc…
anjin: you can create a page with name starting with "_" within a category. It's not then affected by _template.
For example:
Hope this helps
Kritx, just go to http://note.wikidot.com/note:template to see the preview of working _template okay?
I think the "live templates" aren't templates. They're rather useful for the layout/rendering of pages. We should call them layout, for instance. Old templates on the contrary rather are templates, i.e. they allow preparing a model for a catégory of pages. Using both words template / layout avoids such a confusion.
In fact , there seems to be a double difference between old and live templates :
Regular templates should also be optionally dynamic. Dynamic means that when you change the template, all pages will automatically change : this is an imposed model. But sometimes you only want a proposed model that the creator or editor of a page can change, in which case the mtemplate must be static.
Good that you can guide the layout of a category of pages. But I find the section splitting system rather complicated, espacially for public wikis with 'normal', non technical, editors.
I have implemented a template that looks like this:
The problem is with the date_edited field. The result of this page looks something like this:
As you can see, the edit field prints correctly but the date_edited field simply isn't recognized.
Any hints for me?