User:Addyrielle/Helpful notes

From YPPedia

This page has some helpful notes for my own use =).


Art-Ezmerelda M-Note.png General Notes (Click "Show" to view)


Art-Ezmerelda M-Note.png From Wikipedia's Help:Template (Click "Show" to view)


Art-Ezmerelda M-Note.png Creating & Editing Templates (Click "Show" to view)

From Belthazar's Eggy Forum Post

Thanks to the lovely Belthazar =D

Essentially, the {{{1}}} is a parameter placeholder - the parameters are the things you put between the pipe symbols in a template call. For example, {{Renderegg}} is a template. If I call the template with {{Renderegg|2009|4|Fizz}}, then the 2009, 4 and Fizz are all parameters - by default, they're numbered in order: 1, 2 and 3.

If you look at the renderegg template page, you'll notice it reads:

{{Renderegg/{{{2}}}|filename={{{3}}}|year={{{1}}}}}

When the wiki software parses this, it inserts the first parameter wherever a {{{1}}} appears, the second wherever a {{{2}}} appears, and the third wherever a {{{3}}} appears, etc. So if I insert the parameters from my example above, this becomes:

{{Renderegg/4|filename=Fizz|year=2009}}

(Note: this example might be a little confusing, because the Renderegg template actually calls a series of sub-templates depending on what year it is, and how many eggs you have. And the sub-templates have named parameters rather than numbered parameters. But you get what I mean, I hope. I can continue the explanation, but I don't think you need to understand nested sub-templates to understand parameters.)

So, getting back to my idea, what I've done is replaced the template name itself with a parameter placeholder. That is, instead of calling {{Renderegg|2009|4|Fizz}}, I'm using {{{{{1}}}|2009|4|Fizz}}.

Move up a layer to the page where I call this pseudo-template, I've got {{:Pagename|Renderegg}}. "Renderegg" here is parameter number 1, so the wiki software inserts it wherever a {{{1}}} appears on the called page, and so we get {{Renderegg|2009|4|Fizz}}.


Yes.. I think I am following, though, how does it insert Flategg with just the 1 parameter?


Same deal - you're calling the dummy page with a completely different call, and this time you're inserting "Flategg" as the parameter. So {{:Pagename|Flategg}} would replace every occurrence of {{{1}}} in the page Pagename with "Flategg" just as {{:Pagename|Renderegg}} would replace every occurrence of {{{1}}} in the page Pagename with "Renderegg".

Essentially, your dummy page would be exactly the text of your current Renderegg page (sans the opening blurb) but with {{{1}}} in place of the template name. Then you'd reproduce the list on the Renderegg page by putting {{:Pagename|Renderegg}}, and on the Flategg page by putting {{:Pagename|Flategg}}.

(Mind you, there is a simpler solution - just have everything on one page. Instead of having all the rendered images and all the flat images on separate pages, just have them together. As in Flat1, Render1, Flat2, Render2, etc. It'd require re-doing the templates a little, but it's not too complicated. As to whether it's preferable is another matter altogether. =D )


1. Dummy page Let's call it George, so it's clear I'm using a unique name. Here you'd have a full list of all the entrants, written out just as the pages currently look, but with no opening blurb and {{{1}}} in place of the template name. This is the page you do all the editing. Like so:

{{TOCright}}

==Pirate1==

{{{{{1}}}|2009|4|Pirate1}}

==Pirate2==

Design 3 does not have enough bananas. {{{{{1}}}|2009|6|Pirate2}}

==Pirate3==

{{{{{1}}}|2009|1|Pirate3}}

<etc>

Maybe even a <includeonly>'d Category tag at the bottom or something.

2. Renderegg page Here we call our list of data as though it's a template, using "Renderegg" as parameter number 1. The data will be transcluded, but with all occurrences of "{{{1}}}" replaced by "Renderegg". There's no need to edit this page once it's been created - it just automagically updates when you update the dummy page. Viz:

Opening blurb. Welcome to Renderegg page, etc.



{{:George|Renderegg}}


3. Flategg page Exactly the same, only we have a unique opening blurb, and the data page is called using "Flategg" as the parameter instead. Note it's exactly the same data, so exactly the same page, only this time we're replacing "{{{1}}}" with "Flategg" when it gets included. Again, there's no need to edit this page after it gets created. Viz:


Opening blurb. Welcome to Flategg page, etc.



{{:George|Flategg}}

Including one page inside another doesn't change the one page, meaning we can still include it in other pages. That's the wonder of templates. =)


They're called templates rather than scripts, and anyone can view them (though you have to be a logged-in user to edit them). You'll find them at Template:Renderegg and Template:Flategg

The sub-templates is where things get a little complicated. As I noted above, the Renderegg template reads:

{{Renderegg/{{{2}}}|filename={{{3}}}|year={{{1}}}}}

When parsed, the wiki software inserts parameters 1, 2 and 3 where the placeholders are - this is a function of the MediaWiki software itself, and not of the template. I'm reasonably sure it's open source if you want to get a hold of that and inspect how it does thing.


Now, you'll notice once the paramteres have been added, that this template is calling another sub-template. So, say I call the Renderegg template with {{Renderegg|2009|1|Fizz) (i.e. it's 2009 and Fizz has made one egg), when I substitute the values, I get:

{{Renderegg/1|filename=Fizz|year=2009}}

So, this is calling a second template called Template:Renderegg/1. There's a separate sub-template for each number of eggs. I've used the /1 template because it's pretty short... as opposed to (say) the /14 template. =)

So, the /1 template reads: [[{{Renderegg/{{{year}}}}}{{{filename}}}-1.png]]

Passing in the values from before (note here that the sub-template has named parameters, which were also named in the template call above) we get

[[{{Renderegg/2009}}Fizz-1.png]]

Note, this is calling yet another sub-template, Template:Renderegg/2009. This one simply reads:

Image:Egg-rendered-2009-

So, we've reached the end of our string of sub-templates. Now for the magic of templates, the entire text of the template is back-substituted wherever the template call occurs (this process is called "inclusion" or "transclusion" depending on which part of the wiki you're looking at). So if we substitute this into our /1 sub-template above, we get

[[Image:Egg-rendered-2009-Fizz-1.png]]

which you'll recognise as being an image link. Clever, hey? The higher-numbered sub-templates have links for images two, three, four, and so on, which means that rather than having to type out fourteen image links to get fourteen images, we can just type {{Renderegg|2009|14|Dread Pirate Westley}} and it'll generate all the code itself from substitution of the templates and sub-templates.

The Flategg template and sub-templates are exactly the same, except they have "flat" wherever it says "render" or "rendered".

Possibly an easier way to think of it is as a more powerful version of Word's find/replace function. I've asked it to find every ocurrence of the word {{Renderegg}} on a page and replaced it with a image link. The more powerful bit comes in the parameters. Parameters let you do clever things.