Difference between revisions of "Template:List"

From Twinsuniverse
Jump to: navigation, search
(Created page with "<includeonly>{{ #ifexpr: ({{#if:{{{1|}}}|1|0}} + {{#if:{{{2|}}}|1|0}} + {{#if:{{{3|}}}|1|0}} + {{#if:{{{4|}}}|1|0}} + {{#if:{{{5|}}}|1|0}} + {{#if:{{{6|}}}|1|0}} + {{#if:{{{7|...")
 
(added the highly needed 'implode' functionality and updated documentation)
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<includeonly>{{
 
<includeonly>{{
#ifexpr: ({{#if:{{{1|}}}|1|0}} + {{#if:{{{2|}}}|1|0}} + {{#if:{{{3|}}}|1|0}} + {{#if:{{{4|}}}|1|0}} + {{#if:{{{5|}}}|1|0}} + {{#if:{{{6|}}}|1|0}} + {{#if:{{{7|}}}|1|0}} + {{#if:{{{8|}}}|1|0}} + {{#if:{{{9|}}}|1|0}} + {{#if:{{{10|}}}|1|0}}) > 1
+
#vardefine: str|}}{{
|<ul>{{
+
#vardefine: arg|1}}{{
    #if: {{{1}}}| <li>{{{1}}}</li>}}{{
+
#while:
    #if: {{{2}}}| <li>{{{2}}}</li>}}{{
+
|{{{ {{#var: arg}}|}}}{{#ifexpr: {{{range|0}}} >= {{#var: arg}}|true}}
    #if: {{{3}}}| <li>{{{3}}}</li>}}{{
+
|{{#if: {{{ {{#var: arg}}|}}}
    #if: {{{4}}}| <li>{{{4}}}</li>}}{{
+
  |{{#if: {{{separator|}}}|{{#if:{{#var: str}}|{{{separator}}}}}|<nowiki />
    #if: {{{5}}}| <li>{{{5}}}</li>}}{{
+
{{#ifeq: {{{numeric|false}}}|false|*|#}}}}{{{ {{#var: arg}}}}}{{
     #if: {{{6}}}| <li>{{{6}}}</li>}}{{
+
     #vardefine: str|1}}}}{{
    #if: {{{7}}}| <li>{{{7}}}</li>}}{{
+
  #vardefine: arg|{{#expr:{{#var: arg}} + 1}}}}}}
    #if: {{{8}}}| <li>{{{8}}}</li>}}{{
+
</includeonly><noinclude>{{Infobox Template
    #if: {{{9}}}| <li>{{{9}}}</li>}}{{
+
|purpose=formatting
    #if:{{{10}}}|<li>{{{10}}}</li>}}</ul>
+
|singletag=optional
|{{{1|}}}{{{2|}}}{{{3|}}}{{{4|}}}{{{5|}}}{{{6|}}}{{{7|}}}{{{8|}}}{{{9|}}}{{{10|}}}
+
|multiline=optional
}}</includeonly><noinclude>
+
|gamerelated=no
This template wraps up to 10 nonempty strings into an unordered list. If only one string is not empty, it is returned as-is.
+
|suppressible=
 +
|choice=
 +
|cat1=
 +
|var1=arg
 +
}}
 +
 
 +
This template creates a list of a variable amount of (only) non-empty strings. This is useful if the strings are yet to be determined by transclusion context, and only need to be included in the list if they are actually non-empty. The order of the strings will be honoured, in respect to their position number. Gaps are allowed and will be omitted.
 +
 
 +
The list will either use list bullets, or implode the items with a separator into a single string.
 +
 
 +
The list is terminated as soon as it detects an empty string, but this may be turned off for a specified range of strings.
 +
 
 +
 
 +
'''''Note''': Line-breaks in the middle of any of the strings will break the list in two, restarting any numbering, so don't use them.''
  
 
==Parameters==
 
==Parameters==
Ten numbered parameters, no parameter name, case sensitive, all default to not displayed.
+
Unlimited unnamed parameters are accepted, case sensitive, all default to not displayed.
 +
* '''separator''': The string used to glue all values together (any non-empty value will disable list bullets/numbers, which are enabled by default)
 +
* '''numeric''': Whether to render a numeric (ordered) list instead of the default bulleted list (any value other than false will do, defaults to false, ignored if '''separator''' is non-empty)
 +
* '''range''': The minimum number of elements in the list to expect, before empty strings may terminate it (any digit greater than zero, defaults to zero)
 +
 
 +
 
 +
'''''Note''': The '''range''' does not define the resulting size of the list, but only the size within which strings are allowed to be empty. Its value should not be greater than necessary, for best performance.''
  
 
==Syntax==
 
==Syntax==
  <nowiki>{{list
+
  <nowiki>{{list|numeric=yes|separator=string
 
  |string one
 
  |string one
 
  |string two
 
  |string two
 
  |string three
 
  |string three
 
  |...
 
  |...
  |string ten
+
  |string ten-whatnot
 
}}</nowiki>
 
}}</nowiki>
  
 
==Examples==
 
==Examples==
When specifying only five strings:
+
When specifying only three strings:
 
  <nowiki>{{list
 
  <nowiki>{{list
 
  |Ape
 
  |Ape
 
  |Bear
 
  |Bear
  |Chihuahua
+
  |Cow
|Donkey
+
|Eel
+
 
}}</nowiki>
 
}}</nowiki>
  
:<ul>
+
:<ul><li>Ape</li><li>Bear</li><li>Cow</li></ul>
<li>Ape</li>
+
<li>Bear</li>
+
<li>Chihuahua</li>
+
<li>Donkey</li>
+
<li>Eel</li>
+
</ul>
+
  
  
If only one string is specified:
+
If '''numeric''' is specified with any (empty) value other than "false":
 +
<nowiki>{{list|numeric=
 +
|string one
 +
|string two
 +
}}</nowiki>
 +
<nowiki>{{list|numeric=sure
 +
|another string one
 +
|another string two
 +
}}</nowiki>
 +
 
 +
:<ol><li>string one</li><li>string two</li></ol>
 +
:<ol><li>another string one</li><li>another string two</li></ol>
 +
 
 +
 
 +
If the first string is empty or not specified, the list is terminated immediately and no list bullets will be displayed:
 +
<nowiki>{{list||second string is ignored}}</nowiki>
 +
<nowiki>{{list|2=second string is ignored}}</nowiki>
 +
 
 +
 
 +
Similarly, any other empty string will terminate the list as well, ignoring any further strings:
 +
<nowiki>{{list|one|two|three||||seven}}</nowiki>
 +
<nowiki>{{list|one|two|three|7=seven}}</nowiki>
 +
 
 +
:<ol><li>one</li><li>two</li><li>three</li></ol>
 +
:<ol><li>one</li><li>two</li><li>three</li></ol>
 +
 
 +
 
 +
But if '''range''' is specified and greater than zero, that many strings won't terminate the list even if they are empty:
 +
<nowiki>{{list|range=6|one|two|three||||seven||nine}}</nowiki>
 +
 
 +
:<ol><li>one</li><li>two</li><li>three</li><li>seven</li></ol>
 +
 
 +
 
 +
Avoid using line-breaks within any of the strings, because they will totally mess up the list:
 +
<nowiki>{{list|numeric=yes
 +
|one string that has a
 +
multi-line value
 +
|another}}</nowiki>
 +
 
 +
:<ol><li>one string that has a</li></ol>
 +
:multi-line value<ol><li>another</li></ol>
 +
 
 +
 
 +
Instead of listing the strings as individual list items, using '''separator''' will glue them together with the specified string (substitute spaces with the html-entity):
 +
<nowiki>{{list|separator=,&amp;nbsp;|one|two|three}}</nowiki>
 +
 
 +
:one,&nbsp;two,&nbsp;three
 +
 
 +
 
 +
To glue all strings together without a separator, specify an empty span element as '''separator''':
 +
<nowiki>{{list|separator=<span></span>|one|two|three}}</nowiki>
 +
 
 +
:one<span></span>two<span></span>three
 +
 
 +
 
 +
The value of the '''separator''' can be the result of a condition, because it will be ignored if it is empty:
 +
<nowiki>{{list|separator=|one|two|three}}</nowiki>
 +
 
 +
:<ol><li>one</li><li>two</li><li>three</li></ol>
 +
 
 +
 
 +
If only one string is specified, it will still be bulleted or numbered:
 
  <nowiki>{{list|only one string this time}}</nowiki>
 
  <nowiki>{{list|only one string this time}}</nowiki>
 +
<nowiki>{{list|only one string this time|numeric=yes}}</nowiki>
 +
 +
:<ul><li>only one string this time</li></ul>
 +
:<ol><li>only one string this time</li></ol>
  
:only one string this time
 
  
 +
This can be prevented if a single item is expected in advance, by specifying any '''separator''':
 +
<nowiki>{{list|separator=whatever|a single string doesn't get a separator}}</nowiki>
  
If all strings are empty or no string is specified, all are effectively omitted resulting in no display at all.
+
:a single string doesn't get a separator
  
[[Category:Formatting Templates]]
 
 
</noinclude>
 
</noinclude>

Latest revision as of 17:20, 7 June 2014

List
Purpose

Formatting [list all]

Single tag

Optional [list all]

Multi-line

Optional [list all]

Protected

No [list all]

Game related

No [list all]

Categorization
Categories

none [list all]

Variables
Names

One: [list all]

  • arg  (free for reuse)
Subpages

This template creates a list of a variable amount of (only) non-empty strings. This is useful if the strings are yet to be determined by transclusion context, and only need to be included in the list if they are actually non-empty. The order of the strings will be honoured, in respect to their position number. Gaps are allowed and will be omitted.

The list will either use list bullets, or implode the items with a separator into a single string.

The list is terminated as soon as it detects an empty string, but this may be turned off for a specified range of strings.


Note: Line-breaks in the middle of any of the strings will break the list in two, restarting any numbering, so don't use them.

Parameters

Unlimited unnamed parameters are accepted, case sensitive, all default to not displayed.

  • separator: The string used to glue all values together (any non-empty value will disable list bullets/numbers, which are enabled by default)
  • numeric: Whether to render a numeric (ordered) list instead of the default bulleted list (any value other than false will do, defaults to false, ignored if separator is non-empty)
  • range: The minimum number of elements in the list to expect, before empty strings may terminate it (any digit greater than zero, defaults to zero)


Note: The range does not define the resulting size of the list, but only the size within which strings are allowed to be empty. Its value should not be greater than necessary, for best performance.

Syntax

{{list|numeric=yes|separator=string
 |string one
 |string two
 |string three
 |...
 |string ten-whatnot
}}

Examples

When specifying only three strings:

{{list
 |Ape
 |Bear
 |Cow
}}
  • Ape
  • Bear
  • Cow


If numeric is specified with any (empty) value other than "false":

{{list|numeric=
 |string one
 |string two
}}
{{list|numeric=sure
 |another string one
 |another string two
}}
  1. string one
  2. string two
  1. another string one
  2. another string two


If the first string is empty or not specified, the list is terminated immediately and no list bullets will be displayed:

{{list||second string is ignored}}
{{list|2=second string is ignored}}


Similarly, any other empty string will terminate the list as well, ignoring any further strings:

{{list|one|two|three||||seven}}
{{list|one|two|three|7=seven}}
  1. one
  2. two
  3. three
  1. one
  2. two
  3. three


But if range is specified and greater than zero, that many strings won't terminate the list even if they are empty:

{{list|range=6|one|two|three||||seven||nine}}
  1. one
  2. two
  3. three
  4. seven


Avoid using line-breaks within any of the strings, because they will totally mess up the list:

{{list|numeric=yes
 |one string that has a
multi-line value
 |another}}
  1. one string that has a
multi-line value
  1. another


Instead of listing the strings as individual list items, using separator will glue them together with the specified string (substitute spaces with the html-entity):

{{list|separator=,&nbsp;|one|two|three}}
one, two, three


To glue all strings together without a separator, specify an empty span element as separator:

{{list|separator=<span></span>|one|two|three}}
onetwothree


The value of the separator can be the result of a condition, because it will be ignored if it is empty:

{{list|separator=|one|two|three}}
  1. one
  2. two
  3. three


If only one string is specified, it will still be bulleted or numbered:

{{list|only one string this time}}
{{list|only one string this time|numeric=yes}}
  • only one string this time
  1. only one string this time


This can be prevented if a single item is expected in advance, by specifying any separator:

{{list|separator=whatever|a single string doesn't get a separator}}
a single string doesn't get a separator