Anonymous user
Generating tabular output (examples): Difference between revisions
Generating tabular output (examples) (view source)
Revision as of 07:02, 13 April 2022
, 2 years agoFinish (hopefully) the rest of these that need finishing.
imported>FrozenPlum m (Flesh out a whole bunch of these (not finished yet, but it's a good start)) |
imported>FrozenPlum m (Finish (hopefully) the rest of these that need finishing.) |
||
Line 1:
The following tests explain how to use the {{DPL|table}} parameter.
== Include 1 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,
'''Note:''' The <code>%%</code> in <code>tablerow</code> allows precise positioning of the column value, inside whatever formatting you want to apply.
'''Example:'''<br>
Line 15 ⟶ 20:
}}
</pre>
'''Result:'''<br>
Line 24 ⟶ 30:
|count = 5
}}
==Omit (automatic) first column==
This selects articles in [[:Category:Fruit examples]], it includes the "grows" parameter value from "Fruit-Infobox" template. The <code>table</code> statement formats the table as "wikitable" and "sortable" and uses <code>
'''Note:''' If the page name is omitted, and one of the "grows" cells is empty (its page doesn't have a value for "grows" parameter), it appears as an empty row in the table.
'''Example:'''<br>
Line 39 ⟶ 50:
}}
</pre>
'''Result:'''<br>
Line 49 ⟶ 61:
|count = 5
}}
== Move page to 2nd column ==
This selects articles in [[:Category:Fruit examples]], it includes the "grows" parameter value from the "Fruit-Infobox" template, and the page name (<code>%PAGE%</code> gives name ''with'' namespace, if applicable)
'''Note:''' Linking a page name can be done in an <code>{{DPL|include}}</code> statement, though [[mw:Help:Magic words|magic words]], [[mw:Help:Extension:ParserFunctions|parser functions]], and other formatting needs to be done in the tablerow statement.
'''Example:'''<br>
Line 59 ⟶ 76:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:[[%PAGE%|%TITLE%]]
|table =
|tablerow =
|count = 5
}}
</pre>
'''Result:'''<br>
Line 69 ⟶ 87:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:[[%PAGE%|%TITLE%]]
|table =
|tablerow =
|count = 5
}}
== Move page to 2nd column and format==
This selects articles in [[:Category:Fruit examples]], it includes the "grows" parameter value from "Fruit-Infobox" template, and the page (with namespace). The <code>table</code> statement uses <code>-</code> in second position to omit the (automatic) page column
'''Example:'''<br>
Line 82 ⟶ 102:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:%PAGE%
|table =
|tablerow = %%,
|count = 5
}}
</pre>
'''Result:'''<br>
Line 92 ⟶ 113:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:%PAGE%
|table =
|tablerow = %%,
|count = 5
}}
==Include multiple template values==
Multiple template parameter values can be added, these can also be formatted in the <code>include</code> statement. This example selects articles in [[:Category:Fruit examples]] and includes the page title, the "image" parameter value, and the "grows" parameter value. The <code>table</code> statement formats the table, omits the regular (automatic) linked page name first column (so it can be manually inserted without link the <code>tablerow</code> line) and then creates the page headers. The <code>tablerow</code> line formats the plain (unlinked) title in italics, followed by "image" parameter value formatted as a [[mw:Help:Images#Rendering a single image|rendered image]] at 30 pixels wide, and the unformatted "grows" parameter value is displayed last.
<pre>
{{#dpl:
|category = Fruit examples
|include = {Fruit-Infobox}:%TITLE%:image:grows
|table = ,-,Page Name, Image, Grows
|tablerow = <i>%%</i>,[[File:%%|30px]],%%
|count = 5
}}
</pre>
{{#dpl:
|category = Fruit examples
|include = {Fruit-Infobox}:%TITLE%:image:grows
|table = ,-,Page Name, Image, Grows
|tablerow = <i>%%</i>,[[File:%%|30px]],%%
|count = 5
}}
== Include multiple (different) template's values==
This selects articles in [[:Category:Fruit examples]] whose article names are automatically generated and placed in the first column. It then includes the "Fruit-Infobox" template "grows" parameter value in the second column, and the "Color" template's first (numbered parameter) <code>1</code>
▲'''Notes:'''
* <code>%%</code> values can be reused '''in the same column'''.▼
* Since <code>%%</code> caries the corresponding 1:1 column values down from the include statement, they can't be reused '''in other columns''', a {{DPL|#dplvar}} can be set in the original column then used elsewhere to move the values between columns.▼
* '''Templates used multiple times''' on a page are automatically grouped and listed under the same page (the [[Apple]] page uses the "<code><nowiki>{{Color}}</nowiki></code>" twice), since these are grouped under the same page result, the color value <code>%%</code> can only be used to set the style for text color once, which is why the "green" value is red and not green. ▼
'''Example:'''<br>
Line 116 ⟶ 161:
}}
</pre>
'''Notes:'''
▲* <code>%%</code> values can be reused '''in the same column'''.
▲* Since <code>%%</code> essentially "caries" the corresponding 1:1 column values down from the <code>include</code> statement to apply formatting to, they can't be reused '''in ''other'' columns'''
▲* '''Templates used multiple times''' on a page,
* If you need the contents of templates reused on the same page to be displayed on separate lines, see the {{DPL|multisecseparators}} example of how this is done instead of <code>tablerow</code> (by using a combination of <code>include</code>, <code>listseparators</code>, <code>secseparators</code>, and <code>multisecseparators</code> instead.
'''Result:'''<br>
Line 125 ⟶ 177:
|count = 5
}}
== Using a ''surrogate'' template ==▼
This example uses a surrogate (also known as a phantom) template to specify and/or format a single row of results, using named <code><nowiki>{{{grows|}}}</nowiki></code> or numbered <code><nowiki>{{{1|}}}</nowiki></code> parameters. See the source code of [[Template:Fruit-Infobox.templatevalues]].▼
▲This example uses a surrogate (also known as a phantom) template to specify and/or format a single row of results, using [[mw:Help:Templates#Parameters|named]] <code><nowiki>{{{grows|}}}</nowiki></code> or
See {{DPL|include}} for more information on surrogate templates.
'''Example:'''<br>
Line 140 ⟶ 196:
}}
</pre>
'''Result:'''<br>
Line 149 ⟶ 206:
}}
== Using multiple ''surrogate'' templates ==▼
This example uses two surrogate (also known as a phantom) templates to specify and/or format a single row of results, using named <code><nowiki>{{{grows|}}}</nowiki></code> or numbered <code><nowiki>{{{1|}}}</nowiki></code> parameters. See the source code of [[Template:Fruit-Infobox.templatevalues]] and [[Template:Color.templatevalues]].▼
▲This example uses two surrogate (also known as a phantom) templates to specify and/or format a single row of results, using [[mw:Help:Templates#Parameters|named]] <code><nowiki>{{{grows|}}}</nowiki></code> or
See {{DPL|include}} for more information on surrogate templates.
'''Example:'''<br>
Line 162 ⟶ 224:
}}
</pre>
'''Result:'''<br>
Line 170 ⟶ 233:
|count = 5
}}
== Get 1 section's contents ==
This example includes the content of article's "Notes" section content, for pages in [[:Category:Fruit examples]] that have a section named "Notes" (pages that don't contain this show no content for it). The sort order is set to descending using <code>tablesortcol</code> to cause descending order sorting.
'''Note:''' If any page contains more than one included section, the page name will appear multiple times in the output with each section's contents (as can be seen below).
'''Example:'''<br>
Line 187 ⟶ 254:
}}
</pre>
'''Result:'''<br>
Line 197 ⟶ 265:
|count = 3
}}
== Get 2 section's contents ==
This example includes article's "Notes" and "More" page section contents, for pages in [[:Category:Fruit examples]] that have these sections. The "More" section content is limited to 15 characters <code><nowiki>#More[15]</nowiki></code>. The <code>tablerow</code> statement has <code>%%</code> for each value that needs to be carried down to the its corresponding table row cell. The second is section is formatted in italics, the output count also limited to 3 results.
'''Note:''' If any article contains more than one of any section, the page name will appear in the output the matching number of times the section appears. If farther sections are included, and these don't have multiple instances, their contents are displayed in both rows (it repeats, as can be observed below).
'''Example:'''<br>
Line 213 ⟶ 284:
}}
</pre>
'''Result:'''<br>
Line 222 ⟶ 294:
|count = 3
}}
==Dummy section trick==
If a #dummy section is added in the include statement (and an empty corresponding column header is also added), this causes unique behavior when the article results contain multiple sections of the same name. The result is that rather than one line per section being output (along with the page name repeating as was the case in [[#Get 1 section's contents|this example]]), the repeats are instead grouped together, each on a separate line, in one table row. The new lines from subsequent templates have been marked to begin in bold.
'''Note:''' Such a trick may not be visually appealing, the other method to achieving this ensures the first column does not repeat because it is specified in a {{DPL|listseparators}} statement, the the other columns can then be formatted and appear normally using a surrogate/phantom template as can be seen in [[Controlling output format/Parameter: multisecseparators (example 3)|multisecseparators (example 3)]].
Line 234 ⟶ 308:
{{#dpl:
|category = Fruit examples
|include = #dummy,#More[30],#Notes
|table = ,Page,,''More'' text,''Notes'' text
|tablerow = ,<i><small>%%</small></i>,<small>%%</small>
Line 241 ⟶ 315:
</pre>
▲'''Result:'''<br>
'''Result:'''<br>
{{#dpl:
|category = Fruit examples
|include = #dummy,#
|table = ,Page,,"More" text,"Notes" text
|tablerow = ,<small>%%</small>,''<small>%%</small>''
Line 259 ⟶ 333:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...]
|table =
|tablerow = <b>%%</b>,<i>%%</i>,%%,%%,%%
|count = 2
Line 265 ⟶ 339:
}}
</pre>
'''Result:'''<br>
Line 270 ⟶ 345:
|category = Fruit examples
|include = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...]
|table =
|tablerow = <b>%%</b>,<i>%%</i>,%%,<i>%%
|count = 2
|debug=0
|