Making default templates work

By LlamaNerdsLlamaNerds

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+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License