Generating tabular output (examples): Difference between revisions

Add example for a (hopefully) good transition in the learning
imported>FrozenPlum
mNo edit summary
imported>FrozenPlum
(Add example for a (hopefully) good transition in the learning)
 
(6 intermediate revisions by the same user not shown)
Line 1:
{{purgenote}}
{{DPL manual|section=Examples|subsection=Generating tabular output}}
{{tocright}}
Line 9 ⟶ 8:
=== Single template value===
 
This selects articles in [[:Category:Fruit examples]] whose article names are automatically generated and placed in the first column (unless chosen to be omitted). It then includes the "Fruit-Infobox" template "grows" parameter value, for each article in the result set, in the second column. The <code>table=</code> statement sets the table styles (if desired) before the first comma, and then sets the header column text. The <code>tablerow=</code> statement can be used to format some or all of the output, '''but starting after''' the page name, so '''it corresponds to the second column'''so it colors the second column green; <code>%%</code> is used to position the value after the formatting. The results are limited to a count of 5.
 
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: tablerow (example 1)|Example}}
{{example|tablerow|base=Controlling output format|eg=1}}
 
'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Examples/Parameter: tablerow (example 1)|Result}}
'''Note:''' The <code>%%</code> in <code>tablerow</code> allows precise positioning of the column value, inside whatever formatting you want to apply.
 
 
'''Note:''' The <code>%%</code> in <code>tablerow</code> allows precise positioning of the column value, inside whatever formatting you want to apply.
'''Example:'''<br>
<!-- The <code>{{DPL|tablerow}}</code> statement is best explained by an example:
<pre>
{{#<dpl:>
category=Help
|category = Fruit examples
titlematch=DPL%
|include = {Fruit-Infobox}:grows
count=4
|table = class="wikitable sortable",Page,The first parameter<br>of the Template Call
includepage ={DPL Manual}:section,%-1[25]
|tablerow = style="background:#eeffee;"¦%%
table =,Title,Sub Title,Last Section (25 chars)
|count = 5
| tablerow = =style="text-align:center;background-color:#eeffeelightyellow;"¦|%%,|%%,
}}
</dpl>
</pre>
<dpl>
category=Help
titlematch=DPL%
count=4
includepage ={DPL Manual}:section,%-1[25]
table =,Title,Sub Title,Last Section (25 chars)
| tablerow = =style="text-align:center;background-color:#eeffeelightyellow;"¦|%%,|%%,
</dpl>
 
The following example includes the use of {{DPL|addpagecounter}} and {{tt|%COUNT%}}, both of which were removed in MediaWiki 1.25.
 
<pre>
'''Result:'''<br>
{{#<dpl:>
category=African Union member states
|category = Fruit examples
nottitlematch=Sudan
|include = {Fruit-Infobox}:grows
addpagecounter=true
|table = class="wikitable sortable",Page,The first parameter<br>of the Template Call
includepage ={Infobox Country or territory}:area:population_estimate,%0[100]
|tablerow = style="background:#eeffee;"¦%%
format =,,\n|style="text-align:right;"|²{#ifexpr:%COUNT%>300¦<big>'''%COUNT%'''</big>¦%COUNT%}²,
|count = 5
table =,Country,Area,Population,Text,#hits
}}
tablerow =style="text-align:right;"|%%,style="text-align:right;"|%%,style="background-color:lightyellow;"|<small>%%</small>,\n|style="text-align:right;"|%%
</dpl>
</pre>
* We select some African countries, we exclude Sudan
* We acquire a piece of meta data about the articles we will find (in our case the usage counter)
* We include two named parameters from a template call, <nowiki>{{Infobox Country or territory}}</nowiki>
* We include a short text passage from the text before the first chapter
* We use the third parameter of <code>{{DPL|format}}</code> to output the usage counter (we could even highlight values above 100 here, for example)
* We highlight usage values above 300
* We define a standard wiki table with the article name in the first column (named "Country")
* We define column headers for transcluded contents and for the usage counter
* We care for right alignment of the numerical values and define a background-color for the text -->
 
 
Line 129 ⟶ 151:
 
 
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Controlling output volumeExamples/Parameter:_include_ include (example 34)|Example}}
{{example|include|base=Controlling output volume|eg=34}}
 
 
'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Examples/Parameter: include (example 4)|Result}}
 
 
===#dplvar to move/duplicate parameters between columns===
 
'''Example:'''<br>
{{#lsth:Examples/Parameter: tablerow (example 2)|Example}}
{{ViewTest|Examples|Parameter: tablerow (example 2)}}
 
'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Controlling output volume/Parameter:_include_(example 3)|Result}}
{{#lsth:Examples/Parameter: tablerow (example 2)|Result}}
 
 
Line 265 ⟶ 297:
===Single surrogate template===
 
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Controlling output formatExamples/Parameter:_table_ table (example 3)|Example}}
{{example|table|base=Controlling output format|eg=3}}
 
'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Controlling output formatExamples/Parameter:_table_ table (example 3)|Result}}
 
===Multiple surrogate templates===
 
Multiple surrogates might be used only if you need to access parameter values from '''different templates''' used on the same page or set of pages; otherwise, it is generally better to use just one.
Anonymous user