Making default templates work

By LlamaNerds LlamaNerds

Description

I was excited to see that wikidot allows default templates for each category of page, however my first experiments with the default template have been disappointing due to the fact that updating a template does not update any pages already created with that template. But, by 'layering' templates, you can make this feature much more useful and user-friendly. Here's how it works:

Code

First, you need to create a layout template. The purpose of the layout template is actually to format the page the way you want it, and use variables to hold the place of the actual content. Let's say you're creating a template to keep track of your music collection. You might have a really simple template that looks like this:

template:music-layout

+ Artist/Band Info
{$artist-name}
{$band-members}
+ Albums
{$album-list}
+ Other information
{$other-info}

Okay, you now have a basic layout template which is fairly easy to rearrange. All it needs is the information to plug in to the place-holder variables. That's where the actual default template comes in. You're going to use the default template to invoke the layout template, and to store the list of variables that you need to fill for the layout template:

template:music-default

 [[include template:music-layout
|artist-name=
|band-members=
|album-list=
|other-info=
]]

Remember to make sure the variables are listed between the double brackets.

In action

So if you had a music page entry for a band named The Munkey Fists, the page would look something like this:

music:munkey-fists

 [[include template:music-layout
|artist-name=The Munkey Fists
|band-members=Joe Spielman, Fred Fandeler, Teri McGoshering
|album-list=Tying the knot, Being Mean to Old Ladies
|other-info=This band has a similar feel to The Flying Buttresses, but with a little less punk and a little more Grunge (okay, I really know very little about music)
]]

link to the implemented solution (on some site?) or put a working example here


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by LlamaNerds


Rate this solution

If you think this solution is useful — rate it up!

rating: +8
page revision: 3, last edited: 16 Feb 2012 01:20
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /