Gehn, lord of ages wrote:Mac_Fife wrote:Parser Functions - Logical and conditional functions - very useful for conditional page transclusion (templates).[/list]
Um, could you give an explanation on what this is for this poor clueless person?
Err, OK, I'll try and give an example, but forgive me if it gets complicated - the point of it is that someone who knows what they're doing does the complicated bit and everyone else gets something that "just works"
Sometimes you want a document to adapt it's content depending on how it's being used. That might sound a bit perverse, but bear with me
. I'll use
templates as an example (coz it's the way I best understand it).
First (for the benefit of anyone who doesn't know), the wiki allows a document to include the contents of a second document. This is handy for inserting things like common banners and avoids you adding in the entire wiki-text of the banner everytime. This process is called
transclusion and the embedded document is usually referred to as a
template. This is what you referred to in the
Wiki Templates thread. To include a template within a document you just insert {{
templatename}} in your main document. OK that's the easy bit.
Now to illustrate (in part) I've created three pages on the wiki, so you might want to look at the wiki-code of these:
Sandbox is a dummy article, to show the use of a template,
Template:Spoiler is the template, which shows a "Spoiler warning" banner,
Template:Spoiler/doc is the documentation on how to use the Spoiler template.
Now to explain (I hope
):
Sandbox starts with the line: {{spoiler}}
This calls up the
Template:Spoiler page (the
Template namespace is assumed by using {{...}} )
Now, if you look at the Spoiler page source you'll see that it has a bit in <div>...</div> tags which the actual template bit, followed by a bit in <noinclude>...</noinclude> tags. The <noinclude> tags tell the wiki not to show that stuff when the template gets included in another page. But it
is used if the
template page itself is viewed. In this case, it's calling another template,
Template:Spoiler/doc, which contains the actual usage information for the
Spoiler template. So why not just put the documentation directly into the
Spoiler document? Well, you can - easily. But, it is often the case that you want to protect the template from edits but still allow others to amend or improve the documentation, and the best way to do that is by having the documentation
transcluded into the template, as per my example.
And you could leave it there, but it's a bit "clunky": You have to remember to create the documentation page, make sure you've got the document names matching properly, etc., so wouldn't it be nice to semi-automate it so you don't screw up?
This is where it gets scary
So, instead of creating a unique link in every template to it's corresponding documentation page (e.g. {{templateA/doc}}, {{templateB/doc}}, etc.) you just simply call up one universal documentation page for
all templates, e.g. {{documentation}}. And this is when you need the parser functions. In the generic
Template:Documentation page you add code to evaluate the title of the page that it has been called into. You can then concatenate the "/doc" bit onto the end to give you name of the page where the documentation should be.
So the "end user" simply creates their template with the generic {{documentation}} call, which initially gives a "red link" to the uncreated documentation page, which can be followed then or later on to add the documentation details, and lo and behold all the related template and documentation page names stay consistent without the user ever needing to know how it all works
.
I hope that makes sense to you