This advanced example template shows the stacking mechanism provided by Module:Params in its full potential (see § The code, explained below). The template itself is similar to {{Pagelist}}, with added:
- automatic recognition of chapters from links containing the hash characters; e.g.:
#Usage→ § UsageThomas Tracy Cobb#Life and career→ Thomas Tracy Cobb § Life and careerModule:String#replace→ Module:String § replace
- automatic recognition of the
Template:namespace; e.g.:Template:Hatnote→ {{Hatnote}}
- automatic recognition of the
Module:namespace; e.g.:Module:Params→ {{#invoke:Params}}
- support for serial comma
Usage
[edit]For instance, writing
{{module:params/doc/examples/universal page list
| #Usage
| Joshua & the Battle of Jericho
| Forest Grove High School
| Thomas Tracy Cobb#Life and career
| Template:Hatnote
| Module:Params
| Module:String#replace
}}
will generate
§ Usage, Joshua & the Battle of Jericho, Forest Grove High School, Thomas Tracy Cobb § Life and career, {{Hatnote}}, {{#invoke:Params}}, and Module:String § replace
The code, explained
[edit]To understand how the stacking mechanism works, here follows a commented version of the example template's code. Make sure to read the small tutorial in the documentation of snapshotting before reading further here.
{{#invoke:params|
excluding_non-numeric_names|<!-- Remove non-numeric parameters -->
all_sorted|<!-- Ensure that the final output is naturally sorted -->
mapping_by_replacing|^%s*:?%s*(.-)%s*$|%1|1|<!-- Remove possible leading colons and spaces; remove possible trailing spaces -->
mapping_by_replacing|^([^#]-)%s*#$|%1|1|<!-- Remove possible trailing hash characters -->
with_value_not_matching||strict|<!-- Remove empty parameters -->
setting|i/l/s|, | and |, and |<!-- Set the separators -->
entering_substack|<!-- Make a copy of the root parameters and work only on it (‘copy 1’) -->
with_value_matching|#|plain|<!-- Remove all parameters that do not contain the hash characters from ‘copy 1’ -->
detaching_substack|<!-- Remove the parameters currently in ‘copy 1’ from the root stack -->
entering_substack|<!-- Make a copy of the parameters in ‘copy 1’ and work only on it (‘copy 2’) -->
with_value_matching|^#|<!-- Remove all parameters that do not begin with the hash characters from ‘copy 2’ -->
detaching_substack|<!-- Remove the parameters currently in ‘copy 2’ from the parent stack (‘copy 1’) -->
mapping_by_replacing|^#%s*(%S.*)$|[[#%1|§ %1]]|1|<!-- Transform the parameters in ‘copy 2’ to links to chapters from the current page -->
leaving_substack|<!-- Put ‘copy 2’ on top of the queue and go back to ‘copy 1’ -->
mapping_by_replacing|^([^#]-)%s*#%s*(%S.*)$|[[:%1#%2|%1 § %2]]|1|<!-- Transform the parameters in ‘copy 1’ to links to chapters from other pages -->
flushing|<!-- Merge ‘copy 2’ into ‘copy 1’ -->
leaving_substack|<!-- Put ‘copy 1’ on top of the queue and go back to the root stack -->
snapshotting|<!-- Make a copy of the root parameters (‘copy 3’) and put it on top of the queue -->
entering_substack|<!-- Enter into the ‘copy 3’ stack and work only on it -->
with_value_matching|^[Tt]emplate%s*:%s*|<!-- Remove all parameters that do not begin with ‘Template:’ or ‘template:’ from ‘copy 3’ -->
detaching_substack|<!-- Remove the parameters currently in ‘copy 3’ from the root stack -->
mapping_by_replacing|^[Tt]emplate%s*:%s*(.-)$|{{[[:Template:%1|%1]]}}|1|<!-- Transform the parameters in ‘copy 3’ to links to templates -->
leaving_substack|<!-- Put ‘copy 3’ on top of the queue and go back to the root stack -->
snapshotting|<!-- Make a copy of the root parameters (‘copy 4’) and put it on top of the queue -->
entering_substack|<!-- Enter into the ‘copy 4’ stack and work only on it -->
with_value_matching|^[Mm]odule:|<!-- Remove all parameters that do not begin with ‘Module:’ or ‘Module:’ from ‘copy 4’ -->
detaching_substack|<!-- Remove the parameters currently in ‘copy 4’ from the root stack -->
mapping_by_replacing|^[Mm]odule%s*:%s*(.-)$|{{[[:Module:%1|#invoke:%1]]}}|1|<!-- Transform the parameters in ‘copy 4’ to links to modules -->
leaving_substack|<!-- Put ‘copy 4’ on top of the queue and go back to the root stack -->
mapping_by_mixing|[[:$@]]|<!-- Transform the parameters in the root stack to regular links -->
flushing|<!-- Merge ‘copy 4’ with the root stack -->
flushing|<!-- Merge ‘copy 3’ with the root stack -->
flushing|<!-- Merge ‘copy 1’ with the root stack -->
list_values<!-- List everything -->
}}