Applying a template to all pages of a given category

From FollowTheScore
Revision as of 08:20, 29 August 2008 by Gero (talk | contribs)
Jump to: navigation, search

How can one apply a template to all pages of a certain category?

Sometimes you want to create a list of articles where each entry in the list points to an adress which is constructed from the article´s name. Basically, this means that you want to produce the equivalent of

{{some template|1st page in category}}
{{some template|2nd page in category}}
{{some template|3rd page in category}}
...

Answer

The way how to do this depends slightly on the mode you use for your DPL call.

Variant 1: function call with <dpl> tag

To invoke a template called "My special article lister" for all pages which are members of category "Fictitious country" you would have to write the following:

<dpl>
category=Fictitious country
format=,{{My special article lister|%PAGE%}}
</dpl>

The result could like this:


Variant 1 (parser function call, all MW versions)

If you want to use parser function syntax there are some differences: If you are using MediaWiki 1.11 or below you cannot use double curly braces or pipe symbols within the dpl call directly. Instead you must use special escape marks for these symbols. Note the broken pipe symbol and the little ² around the single curly braces.

{{#dpl:
 |category=Fictitious country
 |format=,²{My special article lister¦%PAGE%}²
}}

The result looks the same as before:


Variant 2 (parser function call, only MW 1.11 or above)

If you are using MediaWiki 1.11 or above you can use the normal symbols within the DPL text. Because of a parser change MediaWiki does no longer expand those symbols before it invokes DPL. INstead DPL does this for you after it has done its job. %This leads - in principle - to the desired behaviour. But there is still a minor difference: There will be no linefeed inserted between the template calls. So you must either start your template code on line two or you must insert a newline symbol before calling the template:

{{#dpl:
 |category=Fictitious country
 |format=,\n{{My special article lister|%PAGE%}}
}}

The result still looks the same (note that we are using MW 1.13 (or above) in this wiki.