Difference between revisions of "Template:PropVals/Split"
From Salem Wiki
m (correcting logic) |
m (Introducing "sep" parameter and changing default separator tobe a dot-colon) |
||
Line 1: | Line 1: | ||
<onlyinclude>{{#switch: {{{part|head}}} | <onlyinclude>{{#switch: {{{part|head}}} | ||
− | | head = {{#explode: {{{val|Head | + | | head = {{#explode: {{{val|Head;Tail}}} | {{{sep|;}}} }} |
− | | #default = {{#explode: {{{val|Head | + | | #default = {{#explode: {{{val|Head;Tail}}} | {{{sep|;}}} |{{#ifeq: {{{part|tail}}}|tail | -1 | {{{part}}} }} }} |
}}</onlyinclude><noinclude>{{documentation}}</noinclude> | }}</onlyinclude><noinclude>{{documentation}}</noinclude> |
Revision as of 14:04, 20 June 2012
Head
Template documentation (for the template shown above, sometimes hidden or invisible)
Description
- This template is used to split the parts of a property's value using a separator.
- See these pages for documentation on functions used:
Syntax
- Type the below code somewhere on a page:
{{PropVals/Split}}
- It can accept 3 named-parameters:
- val
- Mandatory; The value to split. Defaults to "Head;Middle;Tail"
- part
- Optional; The part to fetch, and can be:
- 'head' = Fetch first part. (default)
- 'tail' = Fetch last part.
- a number = Fetch the #part, this number is directly used by the #explode: function and is Zero-based as explained in its documentation.
- Optional; The part to fetch, and can be:
- sep
- Optional; The separator to use for splitting parts. (defaults to a dot-colon ';')
- val
Examples
- {{PropVals/Split}} and {{PropVals/Split|part=head}} gives:
Head and Head - {{PropVals/Split|part=-1}} and {{PropVals/Split|part=tail}} gives:
Tail and Tail - {{PropVals/Split|part=1}} gives:
Tail - {{PropVals/Split|val=A:B:C|sep=:}} gives:
A - {{PropVals/Split|val=A:B:C|sep=:|part=1}} gives:
B - {{PropVals/Split|val=A:B:C|sep=:|part=tail}} gives:
C
Visit Template:PropVals/Split/doc to edit this text! (How does this work?)