Difference between revisions of "Applying a template to all pages of a given category"

From FollowTheScore
Jump to: navigation, search
Line 3: Line 3:
 
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  
 
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  
  
<nowiki>{{some template|1st page in category}}</nowiki><br>
+
<pre><nowiki>
<nowiki>{{some template|2nd page in category}}</nowiki><br>
+
  {{some template|1st page in category}}
<nowiki>{{some template|3rd page in category}}</nowiki><br>
+
  {{some template|2nd page in category}}
...<br>
+
  {{some template|3rd page in category}}
 +
  ...
 +
</nowiki></pre>
  
 
== Answer ==
 
== Answer ==
Line 17: Line 19:
 
<pre><nowiki>
 
<pre><nowiki>
 
<dpl>
 
<dpl>
category=Fictitious country
+
  category=Fictitious country
format=,{{My special article lister|%PAGE%}}
+
  format=,{{My special article lister|%PAGE%}}
 
</dpl>
 
</dpl>
 
</nowiki></pre>
 
</nowiki></pre>
Line 25: Line 27:
  
 
<dpl>
 
<dpl>
category=Fictitious country
+
  category=Fictitious country
format=,{{My special article lister|%PAGE%}}
+
  format=,{{My special article lister|%PAGE%}}
 
</dpl>
 
</dpl>
  
Line 37: Line 39:
 
<pre><nowiki>
 
<pre><nowiki>
 
{{#dpl:
 
{{#dpl:
|category=Fictitious country
+
  |category=Fictitious country
|format=,²{My special article lister¦%PAGE%}²
+
  |format=,²{My special article lister¦%PAGE%}²
 
}}
 
}}
 
</nowiki></pre>
 
</nowiki></pre>
Line 45: Line 47:
  
 
{{#dpl:
 
{{#dpl:
|category=Fictitious country
+
  |category=Fictitious country
|format=,²{My special article lister¦%PAGE%}²
+
  |format=,²{My special article lister¦%PAGE%}²
 
}}
 
}}
  
Line 55: Line 57:
 
<pre><nowiki>
 
<pre><nowiki>
 
{{#dpl:
 
{{#dpl:
|category=Fictitious country
+
  |category=Fictitious country
|format=,\n{{My special article lister|%PAGE%}}
+
  |format=,\n{{My special article lister|%PAGE%}}
 
}}
 
}}
 
</nowiki></pre>
 
</nowiki></pre>
Line 63: Line 65:
  
 
{{#dpl:
 
{{#dpl:
|category=Fictitious country
+
  |category=Fictitious country
|format=,\n{{My special article lister|%PAGE%}}
+
  |format=,\n{{My special article lister|%PAGE%}}
 
}}
 
}}

Revision as of 08:22, 29 August 2008

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.