Template:ListToText/doc: Difference between revisions
No edit summary |
m 1 revision imported: Initial Setup |
||
(No difference)
| |||
Latest revision as of 09:51, 12 April 2026
| This is a documentation subpage for Template:ListToText. It contains usage information, categories and other content that is not part of the original Template page. |
| Uses Lua: |
Usage
This template concatenates a sequence of items with separators in page language. When there are at least two items, the last two items are instead joined with a conjunction word in page language.
This is useful in translateable pages: if the items are not to be translated, rather than making each item a <tvar>, it's better to list the items with this template and make the whole transclusion a <tvar>.
Parameters
- (Unnamed arguments): The items.
{{{sep}}}: The separator. By default it's{{int|comma-separator}}. (In your interface language it's,.){{{conj}}}: The conjunction word. By default it's{{int|and}}{{int|word-separator}}. (In your interface language it'sand.){{{noconj}}}: If true (see Module:Yesno to learn what is considered as true), still use the separator to join the last two items.{{{fmt}}}: An optional format string with "$1" substring. If given, each item is converted to this string with "$1" replaced with the item. HTML tags are supported. Templates, magic words and extension tags can be parsed but you need to escape them in proper ways. See below to learn more.
(TemplateData to be added)
Examples
- A transclusion with no items given yields nothing:
{{ltt}}→ - One item:
{{ltt|1}}→
1 - Two items:
{{ltt|1|2}}→
1 and 2 - Even more items:
{{ltt|1|2|3|4}}→
1, 2, 3 and 4 - Different separator & no conjunction word:
{{ltt|sep= {{!}} |noconj=1|1|2|3|4}}→
1 | 2 | 3 | 4 - Format string:
{{ltt|fmt=($1)|1|2|3|4}}→
(1), (2), (3) and (4)
Use of format string
HTML tags can be directly used in the format string. They can be rendered correctly.
{{ltt|fmt=<code>$1</code>|1|2|3|4}}→1,2,3and4
However, templates and magic words need escaping with {{((}} and {{))}}, and extension tags with {{^(}} and {{)^}}, or they will be parsed before being passed to the underlying module. Don't use <nowiki></nowiki> or character entities; things may otherwise end up as plain text.
{{ltt|fmt={{((}}tl{{!}}$1{{))}}|((|))|^(|)^}}→
{{((}}, {{))}}, {{^(}} and {{)^}}{{ltt|fmt={{((}}NAMESPACE:$1{{))}}|Help:A|Project:B|Template:C}}→
Help, Project and Template{{ltt|fmt={{^(}}syntaxhighlight inline lang="lua">local $1</syntaxhighlight>|a|b|c}}→local a,local bandlocal c
In translateable pages
If all arguments are not to be translated, you can wrap the whole transclusion with <tvar> like: <tvar name="1">{{ltt|noconj=yes|1|2|3|4}}</tvar>.
If some arguments are to be translated, wrap the template name and not-to-be-translated arguments with <tvar> and leave other things outside, like: {{<tvar name="1">ltt|don't|translate|that</tvar>|translate|this}} (Translators will see {{$1|translate|this}}). Note that if you're using custom separators and conjunction words, they might need to be localized and you need to expose them outside the <tvar> tag.