Predloga:Enum/Item
Outputs the first parameter, followed by a comma if both the second and third parameters are present, or " and " if only the second parameter is present. This is useful in constructing lists so that each item can be output with the appropriate separator ready for the next item in the list.
Optionally, arbitrary text can be output if neither second nor third parameters are specified, that is, if the item is the last in the list. This is useful for adding terminal punctuation such as a full stop, without the need to do decide at a higher level template whether the item is the last.
This is an implementation template intended to be used by other templates; in an article, it is easier simply to write out the list longhand, but in a template this can be complicated if the number of items in the list is unknown.
An alternative way of constructing such a list is to output the separator before each next item in the list, but that still requires knowledge of whether another item is to follow (to decide between the comma and " and ", so the two implementations boil down to the same thing.
Usage
uredi{{Enum|first|second|third}}
The positional parameters are the item in the list to be displayed, the item following it, and the item following that. Any or all the parameters may be missing; blank parameters are treated the same as empty parameters.
The named parameters are:
- after: The text to follow the final item. This might be a semicolon, for example. The default is to have no following text.
- and: The text to use where by default " and " is written. This may be useful if there is a preference for a comma before the "and", or where it makes sense to write it in a language other than English, for example.
- comma: The text to use between items except the last and one-before-last. If not specified, the default is ", ".
Examples
urediThe test cases include a fuller set of examples.
Input | Output |
---|---|
{{Enum|Tom}} |
Tom |
{{Enum|Tom|Dick}} |
Tom in Dick |
{{Enum|Tom|Dick|Harry}} |
Tom, Dick in Harry |
{{Enum|Tom|Dick|Harry|after=.|and=+}} {{Enum|Dick|Harry|after=.|and=+}} {{Enum|Harry|after=.|and=+}}
|
Tom, Dick+Harry.Dick+Harry.Harry. |
This last example shows the intended use, where several invocations of the template, each shifted by one parameter, can be used to construct a list.