Generating tabular output (examples): Difference between revisions

From DynamicPageList3 Manual
Content added Content deleted
fts>Roc michael
imported>FrozenPlum
(Add example for a (hopefully) good transition in the learning)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DPL manual|section=Examples|subsection=Generating tabular output}}
{{Type Test
{{tocright}}
|parameter = table


The following examples explain how to generate tabular output.

==Using template parameter values==
=== Single template value===


'''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.
<!-- The <code>{{DPL|tablerow}}</code> statement is best explained by an example:
<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:lightyellow;"|%%,|%%,
</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:lightyellow;"|%%,|%%,
</dpl>

The following example includes the use of {{DPL|addpagecounter}} and {{tt|%COUNT%}}, both of which were removed in MediaWiki 1.25.
<pre>
<dpl>
category=African Union member states
nottitlematch=Sudan
addpagecounter=true
includepage ={Infobox Country or territory}:area:population_estimate,%0[100]
format =,,\n|style="text-align:right;"|²{#ifexpr:%COUNT%>300¦<big>'''%COUNT%'''</big>¦%COUNT%}²,
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 -->


====Omit (automatic) 1st 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>-</code> 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, <code>tablerow</code> corresponds 1:1 to the include statement, so the ''first'' column is styled green using <code>%%</code> 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:'''<br>
<pre>
{{#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
}}
}}
</pre>


'''Result:'''<br>

{{#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
}}


==== 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) which is linked, using <code>%TITLE%</code> (page name ''without'' namespace) as the link text. The <code>table</code> statement formats the table, then uses <code>-</code> in the second position to omit the first (automatic) page column. With the page column omitted, the <code>tablerow</code> formatting corresponds 1:1 to the include statement and the ''first'' column containing the "grows" parameter value is displayed using <code>%%</code>. The last column uses <code>%%</code> position the value for bold formatting.


The following tests explain how to use the <tt>[[table]]</tt> command. We have a set of documents (starting with ''Some Article ..'') and a test template named ''Some Template'' and ''Some Template.dpl'', respectively.


'''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.
Please note that there is another '''example''' for creative use of the <tt>table</tt> command in the '''[[Talk:Test table|discussion page]]'''.


== A: just get one column from a template invocation ==


'''Example:'''<br>
|include = {Some Template}:parm1
<pre>
|table = ,,The first parameter<br>of the Template Call
|tablerow = bgcolor=#eeffee¦%%
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch = Some Article %
|include = {Some Template}:parm1
|include = {Fruit-Infobox}:grows:[[%PAGE%|%TITLE%]]
|table = ,,The first parameter<br>of the Template Call
|table = ,-,The first parameter<br>of the Template Call,Page
|tablerow = bgcolor=#eeffee¦%%
|tablerow = %%,<b>%%</b>
|count = 5
}}
}}
</pre>


== A: just get one column from a template invocation (sortable table)==


'''Result:'''<br>
|include = {Some Template}:parm1
|table = class=sortable,,The first parameter<br>of the Template Call
|tablerow = bgcolor=#eeffee¦%%
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch = Some Article %
|include = {Some Template}:parm1
|include = {Fruit-Infobox}:grows:[[%PAGE%|%TITLE%]]
|table = class=sortable,,The first parameter<br>of the Template Call
|table = ,-,The first parameter<br>of the Template Call,Page
|tablerow = bgcolor=#eeffee¦%%
|tablerow = %%,<b>%%</b>
|count = 5
}}
}}


== A2: just get one column from a template invocation ==


==== Move page to 2nd column and format====
|include = {Some Template}:parm1
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 which makes the <code>tablerow</code> value corresponds 1:1 to the include statement position. <code>tablerow</code> has no formatting set for the first column, so its content is displayed as-is from the "grows" <code>include</code> statement, and in the second column the page (and title) is linked with italic formatting applied.
|table = ,-,The first parameter of the Template Call

|tablerow = bgcolor=#eeffee¦%%

'''Example:'''<br>
<pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch = Some Article %
|include = {Some Template}:parm1
|include = {Fruit-Infobox}:grows:%PAGE%
|table = ,-,The first parameter<br>of the Template Call
|table = ,-,The first parameter<br>of the Template Call,Page
|tablerow = bgcolor=#eeffee¦%%
|tablerow = %%,<i>[[%PAGE%|%TITLE%]]</i>
|count = 5
}}
}}
</pre>
A single '-' instead of a column name for the hyperlink to the article will suppress that column.
Note that in this configuration articles are completely missing if they do not contain a Call of ''Template:Some Template''.


== B: just get one chapter ==


'''Result:'''<br>
|include = #Chapter X
|table = ,,X
|tablerow = bgcolor=#ffeeee¦%%
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = #Chapter X
|include = {Fruit-Infobox}:grows:%PAGE%
|table = ,-,The first parameter<br>of the Template Call,Page
|table = ,,X
|tablerow = bgcolor=#ffeeee¦%%
|tablerow = %%,<i>[[%PAGE%|%TITLE%]]</i>
|count = 5
}}
}}




===Multiple parameter values===
== B2: one chapter, one line per article ==


Multiple template parameter values can be added, these can also be formatted in the <code>tablerow</code> statement.
|include = #dummy,#Chapter X

|table = ,,,X

|tablerow = ,bgcolor=#ffeeee¦%%
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: include (example 4)|Example}}
{{example|include|base=Controlling output volume|eg=4}}


'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Examples/Parameter: include (example 4)|Result}}


===#dplvar to move/duplicate parameters between columns===

'''Example:'''
{{#lsth:Examples/Parameter: tablerow (example 2)|Example}}
{{ViewTest|Examples|Parameter: tablerow (example 2)}}

'''Result:'''<br><!-- transclude result from subpage-->
{{#lsth:Examples/Parameter: tablerow (example 2)|Result}}


=== 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> value in the third column. The <code>table=</code> statement sets the table style and headings, the <code>tablerow=</code> statement's <code>%%</code> 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:'''<br>
<pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = #dummy,#Chapter X
|include ={Fruit-Infobox}:grows,{color}:1
|table = class="wikitable sortable",Page,Fruit-Infobox <br>template "grows" value, Color template "1" <br>(unnamed parameter) value
|table = ,,,X
|tablerow = ,bgcolor=#ffeeee¦%%
|tablerow = style="background:#eeffee;"¦<i>%%</i>,style="color:%%"¦%%
|count = 5
}}
}}
</pre>
Using a dummy parameter (and adding an empty column header -- set the three commas at 'table=,,,X') leads to only ONE line per article. Not very clean, but it works.

'''Notes:'''
* <code>%%</code> values can be reused '''in the same column'''.
* <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.
* 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>
== C: get two different chapters ==
<pre><nowiki>
|include = #Chapter X,#Chapter Z
|table = ,,X,Z
|tablerow = bgcolor=#ffeeee¦%%,bgcolor=#ffffee¦<i><small>%%</small></i>
</nowiki></pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = #Chapter X,#Chapter Z
|include ={Fruit-Infobox}:grows,{color}:1
|table = class="wikitable sortable",Page,Fruit-Infobox <br>template "grows" value, Color template "1" <br>(unnamed parameter) value
|table = ,,X,Z
|tablerow = bgcolor=#ffeeee¦%%,bgcolor=#ffffee¦<i><small>%%</small></i>
|tablerow = style="background:#eeffee;"¦%%,style="color:%%"¦%%
|count = 5
}}
}}


Note that a new table row is started for every occurence of ''Chapter X'' (being the first chapter mentioned in the include statement). The contents of all other columns (in this case Chapter Z) is only shown in the LAST row of each article. If there are multiple occurencies of Chapter Z, they will be separated by a horizontal line (or ony by a line break if you put a space before the "#Chapter Z" in the iclude statement).


==Using page section contents==
== C2: get two different chapters ==


===Single page section===
|include=#dummy, #Chapter X, #Chapter Z

|table=,,,X,Z
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>
<pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include=#dummy, #Chapter X, #Chapter Z
|include = #notes
|table=,,,X,Z
|table = ,,Notes
|tablerow = style="background:#eeffee;"¦%%
|tablesortcol = -1
|count = 3
}}
}}
</pre>


Again we used the trick with the dummy parameter at <tt>include</tt>. As we put a space before the '#Chapter X' we do not even get horizontal separators betrween the chapter texts.


'''Result:'''<br>
== D: invoke a ''phantom'' template ==
|include = {Some Template}.dpl
|table = ,,T1 - p1, T1 - p2
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = {Some Template}.dpl
|include = #notes
|table = ,,T1 - p1, T1 - p2
|table = ,,Notes
|tablerow = style="background:#eeffee;"¦%%
|tablesortcol = -1
|count = 3
}}
}}
We need two column headers as ''Template:Some Template.dpl'' produces two columns of output




===Multiple page sections===
== D1: use template parameters without ''phantom'' template ==
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.
|include = {Some Template}:parm1:parm2[12]
|table = ,,T1 - p1, T1 - p2



We delimit the contents of parm2 to 12 characters; note that word boundaries are used
'''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).
to cut the text; so we only get the first two words (=10 characters)


'''Example:'''<br>
<pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = {Some Template}:parm1:parm2[12]
|include = #Notes,#More[15]
|table = ,,T1 - p1, T1 - p2
|table = ,,Notes,More
|tablerow = %%,<i>%%</i>
|count = 3
}}
}}
</pre>



== D2: invoke a ''phantom'' template ==
'''Result:'''<br>
|include = #dummy,{Some Template}.dpl2
|table = ,,,Template invocations
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = #dummy,{Some Template}.dpl2
|include = #Notes,#More[15]
|table = ,,,Template invocations
|table = ,,Notes,More
|tablerow = %%,<i>%%</i>
|count = 3
}}
}}
Note: The trick with the dummy column wouldn´t work with ''Template:Some Template.dpl'' because that template produces new columns whenever it is called. So we used a different phantom template here /''Template:Some template.dpl2'') which creates a little table containing the parameters of each invocation.



== E: A combination of all ==
===Dummy section trick===
<pre><nowiki>

|addpagecounter = yes
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.
|include = {Some Template}:parm1:parm2,#Chapter X,#Chapter Z

|table = ,,tpl:parm1,tpl:parm2,Chapter X,Chapter Z,page count

|tablerow = '''%% ''',''%% '',bgcolor=#ffdddd{{!}}%%,bgcolor=#ffffdd{{!}}%%
'''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)]].
|format = ,,\n{{!}}bgcolor=#ddddff{{!}}%COUNT%

</nowiki></pre>

'''Example:'''<br>
<pre>
{{#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
}}
</pre>


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


==Using surrogate templates==
===Single surrogate template===

'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: table (example 3)|Example}}
{{example|table|base=Controlling output format|eg=3}}

'''Result:'''<br><!-- transclude result from subpage-->{{#lsth:Examples/Parameter: 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.


The below example selects pages in [[:Category:Fruit examples]], and the include statement uses two different surrogate (also known as phantom) templates to access values from two separate templates used on the result pages, and sets and formats the output for a single row (which is then re-applied to each row in the table). The first argument of the <code>table</code> statement sets the table styles, the next sets the name "Page" for the first column of values. ('''Remember''', the first column of <code>{{DPL|table}}</code> output is automatically generated by DPL3 unless suppressed with <code>-</code> (in place of "Page"), it also can't be formatted unless suppressed; and, if omitted, the first surrogate template would need to supply and format the first column values.) After the "Page" table header in the example, the rest of the titles are set. The first surrogate template formats the first two columns of results (the "grows" and "image" parameters belong to the "Fruit-Infobox" template used on result pages), and the second surrogate formats the last column (the "color" value belongs to the "Color" template used on result pages).


'''Notes:'''
* <code><nowiki>{{{%PAGE%}}}</nowiki></code> can be used to display the page name (with namespace) '''in any surrogate''' template (these are always passed by DPL3).
* <code><nowiki>{{{%TITLE%}}}</nowiki></code> can be used to display the page name (without namespace) '''in any surrogate''' template (these are always passed by DPL3).
* See {{DPL|include}} for more information on surrogate templates.

'''Example-specific:'''
* <code><nowiki>{{{grows|}}}</nowiki></code> was used to display the "Fruit-Infobox" template "grows" ([[mw:Help:Templates#Named parameters|named]]) parameter value from the result pages (if it existed, left it blank if not).
* <code><nowiki>{{{image|}}}</nowiki></code> was used to display the "Fruit-Infobox" template "image" ([[mw:Help:Templates#Named parameters|named]]) parameter value from the result pages (if it existed, left it blank if not).
* <code><nowiki>{{{1|}}}</nowiki></code> was used to display the "Color" template ([[mw:Help:Templates#Anonymous parameters|anonymous]]) parameter value from the result pages (if it existed, left it blank if not).
* Since the "Color" template was used more than once on some pages, it formats each instance more than once.


'''Example:'''<br>
<pre>
{{#dpl:
|category = Fruit examples
|include = {Fruit-Infobox}.templatevalues,{Color}.templatevalues
|table = class="wikitable sortable",Page,Grows,Image,Color
|count = 5
}}
</pre>


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


==Combining parameter values, page sections, surrogates==

'''Example:'''<br>
<pre>
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...],{Color}.templatevalues
|addpagecounter = yes
|table = ,Page,Grows,Image name, Notes, More, Color
|include = {Some Template}:parm1:parm2,#Chapter X,#Chapter Z
|tablerow = <b>%%</b>,<i>%%</i>,%%,%%,%%
|table = ,,tpl:parm1,tpl:parm2,Chapter X,Chapter Z,page count
|count = 2
|tablerow = '''%% ''',''%% '',bgcolor=#ffdddd{{!}}%%,bgcolor=#ffffdd{{!}}%%
|debug=0
|format = ,,\n{{!}}bgcolor=#ddddff{{!}}%COUNT%
}}
}}
</pre>


== E2: A combination of all ==


'''Result:'''<br>
|include=#dummy,{Some Template}.dpl2,#Chapter X,#Chapter Z
|table=,-,,Template Invocations,Chapter X,Chapter Z
{{#dpl:
{{#dpl:
|category = Fruit examples
|titlematch=Some Article %
|include = {Fruit-Infobox}:grows:image,#Notes[20 more...],#More[20 more...],{Color}.templatevalues
|include=#dummy,{Some Template}.dpl2,#Chapter X,#Chapter Z
|table = ,Page,Grows,Image name, Notes, More, Color
|table=,-,,Template Invocations,Chapter X,Chapter Z
|tablerow = <b>%%</b>,<i>%%</i>,%%,<i>%%</i>
|count = 2
|debug=0
}}
}}


[[Category:Miscellaneous examples]]
Note the '-' as the second parameter for the <tt>table</tt> arguments.
[[Category:DPL Example|{{PAGENAME}}]]

Latest revision as of 01:53, 10 April 2023

Manual Examples Generating tabular output


The following examples explain how to generate tabular output.

Using template parameter values

Single template value

Example:

{{#lsth:Examples/Parameter: tablerow (example 1)|Example}}

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

Result:
{{#lsth:Examples/Parameter: tablerow (example 1)|Result}}


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


Omit (automatic) 1st 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 }}


Multiple parameter values

Multiple template parameter values can be added, these can also be formatted in the tablerow statement.


Example:

{{#lsth:Examples/Parameter: include (example 4)|Example}}

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


Result:
{{#lsth:Examples/Parameter: include (example 4)|Result}}


#dplvar to move/duplicate parameters between columns

Example: {{#lsth:Examples/Parameter: tablerow (example 2)|Example}}

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

Result:
{{#lsth:Examples/Parameter: tablerow (example 2)|Result}}


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 page section contents

Single page section

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 }}


Multiple page sections

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 }}


Using surrogate templates

Single surrogate template

Example:

{{#lsth:Examples/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:Examples/Parameter: 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.


The below example selects pages in Category:Fruit examples, and the include statement uses two different surrogate (also known as phantom) templates to access values from two separate templates used on the result pages, and sets and formats the output for a single row (which is then re-applied to each row in the table). The first argument of the table statement sets the table styles, the next sets the name "Page" for the first column of values. (Remember, the first column of table output is automatically generated by DPL3 unless suppressed with - (in place of "Page"), it also can't be formatted unless suppressed; and, if omitted, the first surrogate template would need to supply and format the first column values.) After the "Page" table header in the example, the rest of the titles are set. The first surrogate template formats the first two columns of results (the "grows" and "image" parameters belong to the "Fruit-Infobox" template used on result pages), and the second surrogate formats the last column (the "color" value belongs to the "Color" template used on result pages).


Notes:

  • {{{%PAGE%}}} can be used to display the page name (with namespace) in any surrogate template (these are always passed by DPL3).
  • {{{%TITLE%}}} can be used to display the page name (without namespace) in any surrogate template (these are always passed by DPL3).
  • See include for more information on surrogate templates.

Example-specific:

  • {{{grows|}}} was used to display the "Fruit-Infobox" template "grows" (named) parameter value from the result pages (if it existed, left it blank if not).
  • {{{image|}}} was used to display the "Fruit-Infobox" template "image" (named) parameter value from the result pages (if it existed, left it blank if not).
  • {{{1|}}} was used to display the "Color" template (anonymous) parameter value from the result pages (if it existed, left it blank if not).
  • Since the "Color" template was used more than once on some pages, it formats each instance more than once.


Example:

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


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


Combining parameter values, page sections, surrogates

Example:

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