Jump to content

Module:ParameterCount/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 06:10, 24 November 2015 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

This module counts the number of parameters that are passed to it. It can be configured to count all parameters, or parameters specified by a template author. This module is only useful in templates. It should not be used on non-template pages.

The module has two functions available, all and main.

all

The all function is used to count all parameters specified to a template, regardless of whether they actually appear in the template.

Basic usage

{{#invoke:ParameterCount|all}}

Examples

If the code {{#invoke:ParameterCount|all}} was added to the {{my example template}} template, the code {{my example template|1|2|foo=bar}} would produce 3.

main

The main function is used to count parameters with specific names. There are two ways of specifying parameters: by name, and using Lua patterns.

By name

{{#invoke:ParameterCount|main|1|2|3|abc|def}}

To specify a parameter by name, simply add the parameter name as a positional parameter.

By pattern

{{#invoke:ParameterCount|main|pattern1=^param%d+$|pattern2=^abc}}

To specify parameters by Lua Ustring pattern, add the pattern to |pattern1=, |pattern2= etc.

Examples

If the code {{#invoke:ParameterCount|main|1|2|abc}} was added to the {{my example template}} template, the code {{my example template|1|2|abc=some value|other=some other value}}</code> would produce 3.

If the code {{#invoke:ParameterCount|main|pattern1=^param%d+$}} was added to the {{my example template}} template, the code {{my example template|param1=a value|param2=another value|param5=yet another value}}</code> would produce 3.

Checking for blanks

{{#invoke:ParameterCount|all|checkblank=no}}
{{#invoke:ParameterCount|main|checkblank=no}}

By default, the module doesn't count parameters whose values contain only whitespace, e.g. |abc=   . If you wish to count all parameters, regardless of their value, use |checkblank=no. This works with both the all and main functions.

Examples

If the code {{#invoke:ParameterCount|all|checkblank=no}} was added to the {{my example template}} template, the code {{my example template|1|2|foo=bar|baz=}}</code> would produce 4.