Templates

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

BrunhildaBrunhilda 1211530951|%e %b %Y, %H:%M %Z|agohover

Has anyone already implemented this? I would like to see it working…

unfold by BrunhildaBrunhilda, 1211530951|%e %b %Y, %H:%M %Z|agohover
More info available from community
GabrysGabrys 1211628952|%e %b %Y, %H:%M %Z|agohover

http://community.wikidot.com/help:template

unfold More info available from community by GabrysGabrys, 1211628952|%e %b %Y, %H:%M %Z|agohover
MagnesMagnes 1212044279|%e %b %Y, %H:%M %Z|agohover

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.

last edited on 1212044334|%e %b %Y, %H:%M %Z|agohover by Magnes + show more
unfold by MagnesMagnes, 1212044279|%e %b %Y, %H:%M %Z|agohover
Robert WRobert W 1212711057|%e %b %Y, %H:%M %Z|agohover

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)

unfold by Robert WRobert W, 1212711057|%e %b %Y, %H:%M %Z|agohover
_templates and renaming pages
alfredo_elejaldealfredo_elejalde 1212815233|%e %b %Y, %H:%M %Z|agohover

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.

unfold _templates and renaming pages by alfredo_elejaldealfredo_elejalde, 1212815233|%e %b %Y, %H:%M %Z|agohover
more variables for Templates Default Content please
David MarseillesDavid Marseilles 1212971692|%e %b %Y, %H:%M %Z|agohover

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

%%content{1}%%

%%content{2}%%

%%content{3}%%

%%content{4}%%

======

^^%%date%%^^
,,%%author%%,,
+ %%title_linked%%
[!--
content to be visible in blog frontpage through ListPages module
--]
====
[!--
extra content not shown by ListPages
--]
====
Via [ ]
[http://(yoursite).wikidot.com/%%page_unix_name%% Permalink]
[!--
credit and permalink
--]
====

[[module Comments]]
KRITXKRITX 1214309026|%e %b %Y, %H:%M %Z|agohover

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 !

unfold by KRITXKRITX, 1214309026|%e %b %Y, %H:%M %Z|agohover
Yeah! More variables would be excelent!
Gabriel RGabriel R 1214526112|%e %b %Y, %H:%M %Z|agohover

I absolutely agree with fortunzfavor… if we had access to more variables then these live templates would be an even more powerful thing!

unfold Yeah! More variables would be excelent! by Gabriel RGabriel R, 1214526112|%e %b %Y, %H:%M %Z|agohover
Won't work
DerekSmithDerekSmith 1214569241|%e %b %Y, %H:%M %Z|agohover

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

unfold Won't work by DerekSmithDerekSmith, 1214569241|%e %b %Y, %H:%M %Z|agohover
Great!!
elishapetersonelishapeterson 1214589137|%e %b %Y, %H:%M %Z|agohover

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.

unfold Great!! by elishapetersonelishapeterson, 1214589137|%e %b %Y, %H:%M %Z|agohover
Useful
mandracomandraco 1215001100|%e %b %Y, %H:%M %Z|agohover

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.

+ Author
%%content%%
+ Genre
%%content%%
+ Description
%%content%%

And then I've got template:book (the old sort of template)

[!-- Insert author's name here --]
=====
[!-- Insert genre here --]
=====
[!-- Insert description here --]

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.

unfold Useful by mandracomandraco, 1215001100|%e %b %Y, %H:%M %Z|agohover
Old Template Unnecessary
daengbodaengbo 1215054539|%e %b %Y, %H:%M %Z|agohover

@mandraco

Just put the sections at the bottom of the _template with the default content, and it will appear on any new page.

unfold Old Template Unnecessary by daengbodaengbo, 1215054539|%e %b %Y, %H:%M %Z|agohover
@daengbo - You're right
mandracomandraco 1215349199|%e %b %Y, %H:%M %Z|agohover

I just discovered that, actually. I should have known there was an easier way. =)

unfold @daengbo - You're right by mandracomandraco, 1215349199|%e %b %Y, %H:%M %Z|agohover
bypass live _templates?
anjinanjin 1215412094|%e %b %Y, %H:%M %Z|agohover

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…

last edited on 1215432056|%e %b %Y, %H:%M %Z|agohover by anjin + show more
unfold bypass live _templates? by anjinanjin, 1215412094|%e %b %Y, %H:%M %Z|agohover
Re: bypass live _templates?
GabrysGabrys 1217019482|%e %b %Y, %H:%M %Z|agohover

anjin: you can create a page with name starting with "_" within a category. It's not then affected by _template.

For example:

categ:_template the template, not affected by _template
categ:_start a regular page in category, not affected by _template
categ:page1 a regular page in category, affected by _template

Hope this helps

unfold Re: bypass live _templates? by GabrysGabrys, 1217019482|%e %b %Y, %H:%M %Z|agohover
Preview when _template works on your site?
Ivan AkiraIvan Akira 1218352024|%e %b %Y, %H:%M %Z|agohover

Kritx, just go to http://note.wikidot.com/note:template to see the preview of working _template okay?

unfold Preview when _template works on your site? by Ivan AkiraIvan Akira, 1218352024|%e %b %Y, %H:%M %Z|agohover
rename live _template ?
spirspir 1219152262|%e %b %Y, %H:%M %Z|agohover

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 :

  • static/included vs. dynamic/called
  • model/template vs. layout/rendering

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.

unfold rename live _template ? by spirspir, 1219152262|%e %b %Y, %H:%M %Z|agohover
Problem with date_edited
samooresamoore 1220178405|%e %b %Y, %H:%M %Z|agohover

I have implemented a template that looks like this:

By %%author%% (%%date|%a, %b %e at %I:%M%p%%, last edited at %%date_edited|%a, %b %e at %I:%M%p%%)

%%content%%

====
putAnnouncementHere

The problem is with the date_edited field. The result of this page looks something like this:

Test announcement

By samoore (Wed, Aug 27 at 06:02PM, last edited at %%date_edited|%a, %b %e at %I:%M%p%%)

This is simply a test. Nothing to write. Really.

As you can see, the edit field prints correctly but the date_edited field simply isn't recognized.

Any hints for me?

unfold Problem with date_edited by samooresamoore, 1220178405|%e %b %Y, %H:%M %Z|agohover
Add a new comment
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.