Difference between revisions of "Template:For Each Unique"
(Created page with "<noinclude>Apply a template to each non-repeating element of a list. Elements that are the same as the preceding element are skipped. (Elements that are repeated after somet...") |
|||
| Line 3: | Line 3: | ||
* Second parameter: delimiter to search for; default is comma | * Second parameter: delimiter to search for; default is comma | ||
* Third parameter: replacement delimiter; default is the search delimiter, or comma+space if none | * Third parameter: replacement delimiter; default is the search delimiter, or comma+space if none | ||
| − | * ''template'': template to apply to each substring (string provided as first parameter; index provided as ''index'') | + | * ''template'': template to apply to each substring (string provided as first parameter; index in non-repeating list provided as ''index'') |
</noinclude><includeonly>{{For Each Unique/Raw|{{{1|}}}|{{#if:{{{2|}}}|{{{2}}}|,}}|{{{3|{{Select|{{{2}}}|, | | </noinclude><includeonly>{{For Each Unique/Raw|{{{1|}}}|{{#if:{{{2|}}}|{{{2}}}|,}}|{{{3|{{Select|{{{2}}}|, | | ||
| param={{#if:{{{2|}}}|1|2}} | | param={{#if:{{{2|}}}|1|2}} | ||
| Line 9: | Line 9: | ||
| template={{{template}}} | | template={{{template}}} | ||
| index=1 | | index=1 | ||
| + | | out index=1 | ||
| value={{#explode:{{{1|}}}|{{#if:{{{2|}}}|{{{2}}}|,}}|0}} | | value={{#explode:{{{1|}}}|{{#if:{{{2|}}}|{{{2}}}|,}}|0}} | ||
| previous= | | previous= | ||
}}</includeonly> | }}</includeonly> | ||
Revision as of 18:35, 24 June 2015
Apply a template to each non-repeating element of a list. Elements that are the same as the preceding element are skipped. (Elements that are repeated after something else—e.g., "A, B, A"—will be repeated in the output. To get true deduplication, ensure that the list is sorted.)
- First parameter: string to split
- Second parameter: delimiter to search for; default is comma
- Third parameter: replacement delimiter; default is the search delimiter, or comma+space if none
- template: template to apply to each substring (string provided as first parameter; index in non-repeating list provided as index)