Generating tabular output (examples): Difference between revisions

From DynamicPageList3 Manual
Content added Content deleted
imported>FrozenPlum
m (FrozenPlum moved page Test table to Generating tabular output (examples) without leaving a redirect)
imported>FrozenPlum
m (transclude back to here)
Line 164: Line 164:
'''Notes:'''
'''Notes:'''
* <code>%%</code> values can be reused '''in the same column'''.
* <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''' in a {{DPL|tablerow}} statement without the use of {{DPL|#dplvar}} to move the values between columns (though a surrogate template can better enable moving column values to other columns in the same result row).
* <code>%%</code> allows the values of a column to be positioned precisely within whatever formatting is to be applied; otherwise, it simply carries the value down from the corresponding <code>include</code> column to its cell, if other formatted values need to appear in columns after it. Given values correspond to the <code>include</code> position, they can't be moved or used between columns, without the use of {{DPL|#dplvar}} (though surrogate templates can better achieve this same goal, allowing values to be used anywhere within the output they format).
* '''Templates used multiple times''' on a page, have their values automatically grouped and listed under the same page line (the [[Apple]] page uses the "<code><nowiki>{{Color}}</nowiki></code>" template twice, so two color names appear), 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.
* '''Templates used multiple times''' on a page, have their values automatically grouped and listed under the same page line (the [[Apple]] page uses the "<code><nowiki>{{Color}}</nowiki></code>" template twice, so two color names appear), 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.
* 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.
* 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.
Line 181: Line 181:
== Using a surrogate template ==
== Using a surrogate template ==


'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Controlling output format/Parameter:_table_(example 3)|Example}}
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 <code><nowiki>{{{1|}}}</nowiki></code> [[mw:Help:Templates#Parameters|numbered]] parameters. See the source code of [[Template:Fruit-Infobox.templatevalues‎‎]].
{{example|table|base=Controlling output format|eg=3}}


'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Controlling output format/Parameter:_table_(example 3)|Result}}


See {{DPL|include}} for more information on surrogate templates.
== Using ''multiple'' surrogate templates ==


Multiple surrogates might be used only if you need to access parameter values from '''different templates''' used on the set of pages; otherwise, it is generally better to use just one.


This selects pages in [[:Category:Fruit examples]], in the <code>table</code> statement, the styles are set in the first position, then the first column's name is set as "Page". Remember, the first column is automatically generated by DPL3 in <code>table</code> statements (and can't be formatted unless omitted with <code>-</code> taking the position of the "Page" table header and then added to the surrogate instead. first column of table output (linked page name) is automatically generated unless intentionally omitted with <code>-</code> after settings includes 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 [[mw:Help:Templates#Parameters|numbered]] <code><nowiki>{{{1|}}}</nowiki></code> parameters. See the source code of [[Template:Fruit-Infobox.templatevalues‎‎]] and [[Template:Color.templatevalues‎‎]]. Since a surrogate template is used to format the output of the "Color" tem
'''Example:'''<br>
<pre>
{{#dpl:
|category = Fruit examples
|include = {Fruit-Infobox}.templatevalues
|table = ,Page,Grows,Image
|count = 5
}}
</pre>


'''Result:'''<br>
{{#dpl:
|category = Fruit examples
|include = {Fruit-Infobox}.templatevalues
|table = ,Page,Grows,Image
|count = 5
}}


== Using ''multiple'' surrogate templates ==


'''Notes:'''
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 <code><nowiki>{{{1|}}}</nowiki></code> [[mw:Help:Templates#Parameters|numbered]] parameters. See the source code of [[Template:Fruit-Infobox.templatevalues‎‎]] and [[Template:Color.templatevalues‎‎]].
* <code><nowiki>{{{%PAGE%}}}</nowiki></code> can be used to access page name (with namespace) in a surrogate template.
* <code><nowiki>{{{%TITLE%}}}</nowiki></code> can be used to access page name (without namespace) in a surrogate template.




Line 219: Line 204:
{{#dpl:
{{#dpl:
|category = Fruit examples
|category = Fruit examples
|table = class="wikitable sortable",Page,Grows,Image,Color
|include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|table = ,Page,Fruit-Infobox<br><code>color=</code>,Fruit-Infobox<br><code>image=</code>,Color<br>(unnamed parameter whose value is specified <code>1</code>
|count = 5
|count = 5
}}
}}
Line 229: Line 214:
{{#dpl:
{{#dpl:
|category = Fruit examples
|category = Fruit examples
|table = class="wikitable sortable",Page,Grows,Image,Color
|include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|table = ,Page,Fruit-Infobox<br><code>color=</code>,Fruit-Infobox<br><code>image=</code>,Color<br>(unnamed parameter whose value is specified <code>1</code>
|count = 5
|count = 5
}}
}}
Line 268: Line 253:


== Get 2 section's contents ==
== 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.
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 allow for precise positioning of its contents in applied formatting (if any) or simply display the value if no formatting is needed. The second is section is formatted in italics, the output count also limited to 3 results.





Revision as of 05:42, 16 April 2022

The following tests explain how to use the 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, for each article in the result set, in the second column. The table= statement sets the table styles (if desired) before the first comma, and then sets the header column text. The tablerow= statement can be used to format some or all of the output, but starting after the page name, so it corresponds to the second columnso it colors the second column green; %% is used to position the value after the formatting. The results are limited to a count of 5.


Note: The %% in tablerow allows precise positioning of the column value, inside whatever formatting you want to apply.


Example:

{{#dpl:
|category   = Fruit examples
|include    = {Fruit-Infobox}:grows
|table      = class="wikitable sortable",Page,The first parameter<br>of the Template Call
|tablerow   = style="background:#eeffee;"¦%%
|count      = 5
}}


Result:
{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:grows |table = class="wikitable sortable",Page,The first parameter
of the Template Call |tablerow = style="background:#eeffee;"¦%% |count = 5 }}


Omit (automatic) first column

This selects articles in Category:Fruit examples, it includes the "grows" parameter value from "Fruit-Infobox" template. The table statement formats the table as "wikitable" and "sortable" and uses - in second position to omit the first (automatic) page column; the "grows" value now appears in the first column. With the first column left off, tablerow corresponds 1:1 to the include statement, so the first column is styled green using %% to position the value after the styling.


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:

{{#dpl:
|category      = Fruit examples
|include       = {Fruit-Infobox}:grows
|table         = class="wikitable sortable",-,The first parameter<br>of the Template Call
|tablerow      = style="background:#eeffee;"¦%%
|count         = 5
}}


Result:

{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:grows |table = class="wikitable sortable",-,The first parameter
of the Template Call |tablerow = style="background:#eeffee;"¦%% |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 (%PAGE% gives name with namespace, if applicable) which is linked, using %TITLE% (page name without namespace) as the link text. The table statement formats the table, then uses - in the second position to omit the first (automatic) page column. With the page column omitted, the tablerow formatting corresponds 1:1 to the include statement and the first column containing the "grows" parameter value is displayed using %%. The last column uses %% position the value for bold formatting.


Note: Linking a page name can be done in an include statement, though magic words, parser functions, and other formatting needs to be done in the tablerow statement.


Example:

{{#dpl:
|category      = Fruit examples
|include       = {Fruit-Infobox}:grows:[[%PAGE%|%TITLE%]]
|table         = ,-,The first parameter<br>of the Template Call,Page
|tablerow      = %%,<b>%%</b>
|count         = 5
}}


Result:
{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:grows:%TITLE% |table = ,-,The first parameter
of the Template Call,Page |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 table statement uses - in second position to omit the (automatic) page column which makes the tablerow value corresponds 1:1 to the include statement position. tablerow has no formatting set for the first column, so its content is displayed as-is from the "grows" include statement, and in the second column the page (and title) is linked with italic formatting applied.


Example:

{{#dpl:
|category      = Fruit examples
|include       = {Fruit-Infobox}:grows:%PAGE%
|table         = ,-,The first parameter<br>of the Template Call,Page
|tablerow      = %%,<i>[[%PAGE%|%TITLE%]]</i>
|count         = 5
}}


Result:
{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:grows:%PAGE% |table = ,-,The first parameter
of the Template Call,Page |tablerow = %%,%TITLE% |count = 5 }}


Include multiple template values

Multiple template parameter values can be added, these can also be formatted in the include statement. This example selects articles in Category:Fruit examples and includes the page title, the "image" parameter value, and the "grows" parameter value. The table statement formats the table, omits the regular (automatic) linked page name first column (so it can be manually inserted without link the tablerow line) and then creates the page headers. The tablerow line formats the plain (unlinked) title in italics, followed by "image" parameter value formatted as a rendered image at 30 pixels wide, and the unformatted "grows" parameter value is displayed last.


Example:

{{#dpl:
|category      = Fruit examples
|include       = {Fruit-Infobox}:%TITLE%:image:grows
|table         = ,-,Page Name, Image, Grows
|tablerow      = <i>%%</i>,[[File:%%|30px]],%% 
|count         = 5
}}


Result:
{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:%TITLE%:image:grows |table = ,-,Page Name, Image, Grows |tablerow = %%,File:%%,%% |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) 1 value in the third column. The table= statement sets the table style and headings, the tablerow= statement's %% values correspond 1:1 with the position of the include statement, and allows each cell to be styled (or variables, parser functions, or other DPL3 modules to be used). The last column reuses its value, to both set the font color and display the parameter value text itself.


Example:

{{#dpl:
|category   = Fruit examples
|include    ={Fruit-Infobox}:grows,{color}:1
|table      = class="wikitable sortable",Page,Fruit-Infobox <br>template "grows" value, Color template "1" <br>(unnamed parameter) value 
|tablerow   = style="background:#eeffee;"¦<i>%%</i>,style="color:%%"¦%%
|count      = 5
}}

Notes:

  • %% values can be reused in the same column.
  • %% allows the values of a column to be positioned precisely within whatever formatting is to be applied; otherwise, it simply carries the value down from the corresponding include column to its cell, if other formatted values need to appear in columns after it. Given values correspond to the include position, they can't be moved or used between columns, without the use of #dplvar (though surrogate templates can better achieve this same goal, allowing values to be used anywhere within the output they format).
  • Templates used multiple times on a page, have their values automatically grouped and listed under the same page line (the Apple page uses the "{{Color}}" template twice, so two color names appear), since these are grouped under the same page result, the color value %% can only be used to set the style for text color once, which is why the "green" value is red and not green.
  • If you need the contents of templates reused on the same page to be displayed on separate lines, see the multisecseparators example of how this is done instead of tablerow (by using a combination of include, listseparators, secseparators, and multisecseparators instead.


Result:
{{#dpl: |category = Fruit examples |include ={Fruit-Infobox}:grows,{color}:1 |table = class="wikitable sortable",Page,Fruit-Infobox
template "grows" value, Color template "1"
(unnamed parameter) value |tablerow = style="background:#eeffee;"¦%%,style="color:%%"¦%% |count = 5 }}


Using a surrogate template

Example:

{{#lsth:Controlling output format/Parameter:_table_(example 3)|Example}}

Page Template:Example/style.css must have content model "Sanitized CSS" for TemplateStyles (current model is "plain text").

Result:
{{#lsth:Controlling output format/Parameter:_table_(example 3)|Result}}

Using multiple surrogate templates

Multiple surrogates might be used only if you need to access parameter values from different templates used on the set of pages; otherwise, it is generally better to use just one.

This selects pages in Category:Fruit examples, in the table statement, the styles are set in the first position, then the first column's name is set as "Page". Remember, the first column is automatically generated by DPL3 in table statements (and can't be formatted unless omitted with - taking the position of the "Page" table header and then added to the surrogate instead. first column of table output (linked page name) is automatically generated unless intentionally omitted with - after settings includes uses two surrogate (also known as a phantom) templates to specify and/or format a single row of results using named {{{grows|}}} or numbered {{{1|}}} parameters. See the source code of Template:Fruit-Infobox.templatevalues‎‎ and Template:Color.templatevalues‎‎. Since a surrogate template is used to format the output of the "Color" tem

Notes:

  • {{{%PAGE%}}} can be used to access page name (with namespace) in a surrogate template.
  • {{{%TITLE%}}} can be used to access page name (without namespace) in a surrogate template.


See include for more information on surrogate templates.


Example:

{{#dpl:
|category   = Fruit examples
|table      = class="wikitable sortable",Page,Grows,Image,Color
|include    = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|count      = 5
}}


Result:
{{#dpl: |category = Fruit examples |table = class="wikitable sortable",Page,Grows,Image,Color |include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues |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 tablesortcol 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:

{{#dpl:
|category   = Fruit examples
|include    = #notes
|table    = ,,Notes
|tablerow = style="background:#eeffee;"¦%%
|tablesortcol = -1
|count         = 3
}}


Result:
{{#dpl: |category = Fruit examples |include = #notes |table = ,,Notes |tablerow = style="background:#eeffee;"¦%% |tablesortcol = -1 |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 #More[15]. The tablerow statement has %% for each value that allow for precise positioning of its contents in applied formatting (if any) or simply display the value if no formatting is needed. 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:

{{#dpl:
|category   = Fruit examples
|include    = #Notes,#More[15]
|table      = ,,Notes,More
|tablerow   = %%,<i>%%</i>
|count      = 3
}}


Result:
{{#dpl: |category = Fruit examples |include = #Notes,#More[15] |table = ,,Notes,More |tablerow = %%,%% |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 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 listseparators statement, the the other columns can then be formatted and appear normally using a surrogate/phantom template as can be seen in multisecseparators (example 3).


Example:

{{#dpl:
|category   = Fruit examples
|include    = #dummy,#More[30],#Notes[30]
|table      = ,Page,,''More'' text,''Notes'' text
|tablerow   = ,<i><small>%%</small></i>,<small>%%</small>
|count      = 5
}}


Result:
{{#dpl: |category = Fruit examples |include = #dummy,#More[30],#Notes[30] |table = ,Page,,"More" text,"Notes" text |tablerow = ,%%,%% |count = 5 }}


Combination of parameters and sections

Example:

{{#dpl:
|category   = Fruit examples
|include    = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...]
|table      = ,Page,Grows,Image name, Notes, More
|tablerow   = <b>%%</b>,<i>%%</i>,%%,%%,%%
|count = 2
|debug=0
}}


Result:
{{#dpl: |category = Fruit examples |include = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...] |table = ,Page,Grows,Image name, Notes, More |tablerow = %%,%%,%%,%% |count = 2 |debug=0 }}