Jump to content

Generating tabular output (examples)

From DynamicPageList3 Manual
Manual Examples Generating tabular output


The following examples explain how to generate tabular output.

Using template parameter values

[edit source]

Single template value

[edit source]

Example:

This lists pages in category Fruit examples, article titles automatically placed in the first column as a link (unless suppressed). It then include to include the {{Fruit-Infobox}} template's "grows" parameter value for each article, in the second column. The table statement's first argument sets the table styles, the rest set the remaining header text. Since the first column was automatically generated (not intentionally suppressed using - in the second table argument), the first argument of tablerow corresponds to, and formats, the second column; it sets the cell background style (green) and then uses %% to position the value after the formatting and results are limited to a count of 5.

Code
{{#dpl:
|category = Fruit examples
|include  = {Fruit-Infobox}:grows
|table    = class="wikitable sortable",Page,The first parameter<br>value of template used
|tablerow = class="dpl-green-background"¦%%
|count    = 5
}}
Result
Page The first parameter
value of template used
Apple On trees
Grape On vines
Orange On trees
Plum
Banana On a tree-like plant

Result:


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


Omit (automatic) 1st column

[edit source]

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:

The first parameter
of the Template Call
On trees
On vines
On trees
On a tree-like plant


Move page to 2nd column

[edit source]

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:

The first parameter
of the Template Call
Page
On trees Apple
On vines Grape
On trees Orange
Plum
On a tree-like plant Banana


Move page to 2nd column and format

[edit source]

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:

The first parameter
of the Template Call
Page
On trees Apple
On vines Grape
On trees Orange
Plum
On a tree-like plant Banana


Multiple parameter values

[edit source]

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


Example:

This lists pages in category Fruit examples and uses include to include from the Fruit-Infobox template, the variable for page title (%TITLE%), and the "image" and "grows" parameter values. In the table statement, the first argument adds CSS classes to the table, the second "-" deliberately omits the (automatic) linked page name from the first column, and the rest specify column headings.

The tablerow parameter essentially allows the values it holds to be precisely positioned within any formatting applied; the %TITLE% (first) value of the include is carried down to the first column by specifying %% in first position of the tablerow statement. The title is then wrapped in a <span></span> with formatting to make it italic. The next argument carried down is the "image" value (using %%) adding content before and after to format it as a rendered image at 30 pixels wide. The last tablerow argument %% displays the results of the "grows" parameter, this time without added formatting.

Important notes:

  • The include and tablerow parameters work together as a pair (table also).
  • The tablerow parameter essentially allows values to be precisely positioned within any basic formatting it applies.
  • Using %% caries down each value from the include statement, to the same position in the tablerow statement, though this is affected by the automatic creation of a first column containing linked page name (which we've used - in second position of the table statement to suppress).


Code
{{#dpl:
|category = Fruit examples
|include  = {Fruit-Infobox}:%TITLE%:image:grows
|table    = class="wikitable sortable",-,Page Name, Image, Grows
|tablerow = <span style="font-style: italic;">%%</span>,[[File:%%|30px]],%% 
|count    = 5
}}
Result
Page Name Image Grows
Apple On trees
Grape On vines
Orange On trees
Plum
Banana On a tree-like plant


Result:


#dplvar to move/duplicate parameters between columns

[edit source]

Example: This lists pages from category Fruit examples, sets include to include the {{Fruit-Infobox}} template's "grows" parameter value, in first column, the full page name %PAGE% (including namespace) in the second, an intentionally blank/null parameter name in the third (to hold position for the next parameter), and finally the "image" (name) as the last. The table statement's first argument sets table's styles, the second uses - to suppress the otherwise automatic first column (with linked page name), then specifies the column headers for the 4 columns.

The tablerow statement sets a #dplvar (variable) named "varGrows", and specifies its corresponding include value "grows" using %%; and, as setting a variable doesn't also display that variable, %% is used again in that column to display it. Next, the page/title is linked to and set to italic, followed by repeating the value of column 1 in column 3 by calling it by variable name; that was done because the values otherwise cannot be used in columns outside the column order set in include, where setting the variable in the first column enables its use in the third column. Finally, the image (name) value %% is displayed in the fourth (last) column. Results are limited to a count of 5.

Code
{{#dpl:
|category = Fruit examples
|include  = {Fruit-Infobox}:grows:%PAGE%:<!--blank-->:image
|table    = class="wikitable mw-collapsible",-,1st col,2nd col,3rd col,4th col
|tablerow = ²{#dplvar:set¦varGrows¦%%}²%%,<i>[[%PAGE%|%TITLE%]]</i>,²{#dplvar:varGrows}²,%%
|count    = 5
}}
Result
1st col 2nd col 3rd col 4th col
On trees Apple On trees Red Apple Fruit With Black Background.jpeg
On vines Grape On vines Grapes on White Table.jpeg
On trees Orange On trees Orange, orange peel.jpg
Plum Plum on tree.jpg
On a tree-like plant Banana On a tree-like plant Banana-Single.jpg

Result:


Include multiple (different) template's values

[edit source]

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:

Page Fruit-Infobox
template "grows" value
Color template "1"
(unnamed parameter) value
Apple On trees red

green

Grape On vines purple
Orange On trees
Plum
Banana On a tree-like plant


Using page section contents

[edit source]

Single page section

[edit source]

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:

Content page Notes
Orange
Grape
Apple

There are multiple varieties of apples; thus apples can be different colors.

Apples can also be green.

Apple

Apples skins contain more fiber than the rest of an apple.


Multiple page sections

[edit source]

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:

Content page Notes More
Apple

There are multiple varieties of apples; thus apples can be different colors.

Apples can also be green.

This is some ..→

Apple

Apples skins contain more fiber than the rest of an apple.

This is some ..→

Grape
Orange


Dummy section trick

[edit source]

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:

Page "More" text "Notes" text
Apple

This is some more content ..→

There are multiple varieties ..→
Apples skins contain ..→

Grape
Orange
Plum
Banana

This is some more content ..→
This is even more ..→


Using surrogate templates

[edit source]

Single surrogate template

[edit source]

Example:

This lists pages in category Fruit examples and includes the contents of the {{Fruit-Infobox.templatevalues}} surrogate formatting template. The table parameter sets the tale styles and headers, and since it does not include a - in second place to suppress the automatically linked page titles in first place, it formats only the second and third columns of results.

If - was in second position for table, the first column would drop off and the page name would need to be added to table statement or surrogate template, its value could be called or used like a normal parameter {{{%PAGE%}}} using it variable name.

Code
{{#dpl:
|category = Fruit examples
|include  = {Fruit-Infobox}.templatevalues
|table    = class="wikitable sortable",Page,Grows,Image
|count    = 2
}}
Result
Page Grows Image
Apple On trees
Grape On vines

Result:

Multiple surrogate templates

[edit source]

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:

Page Grows Image Color
Apple On trees red

green

Grape On vines purple
Orange On trees
Plum
Banana On a tree-like plant


Combining parameter values, page sections, surrogates

[edit source]

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:

Page Grows Image name Notes More Color
Apple On trees Red Apple Fruit With Black Background.jpeg

There are multiple more...

Apples skins more...

This is some more more...

red

green

Grape On vines Grapes on White Table.jpeg purple
Cookies help us deliver our services. By using our services, you agree to our use of cookies.