- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
Difference between revisions of "Help:Parser functions"
m (expand) |
m (→randint: add #ordinal) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | ==Custom parser functions== | + | {{ambox|type=orange|text=This page is not yet complete!}} |
+ | = Custom parser functions = | ||
+ | == String functions == | ||
+ | |||
+ | === char === | ||
+ | Returns a [[CP437]] character. | ||
+ | |||
+ | Example: <pre>{{#char:1}}</pre> | ||
+ | → {{#char:1}} | ||
+ | |||
=== strc === | === strc === | ||
− | Example:<pre></pre> | + | Expands backslash escape sequences, such as: |
− | + | ||
+ | {|class="wikitable" | ||
+ | ! Text !! Produces | ||
+ | |- | ||
+ | | \n || newline | ||
+ | |- | ||
+ | | \t || tab | ||
+ | |} | ||
+ | |||
+ | Example: <pre>Some example{{#strc:\t}}text</pre> | ||
+ | Produces: | ||
+ | {{#tag:pre|Some example{{#strc:\t}}text}} | ||
=== strcount === | === strcount === | ||
− | Example:<pre></pre> | + | Returns the number of occurrences of the second parameter in the first parameter. Case-sensitive |
− | → | + | |
+ | Example: <pre>{{#strcount:This string sure has a lot of "T"'s in it! | t}}</pre> | ||
+ | → {{#strcount:This string sure has a lot of "T"'s in it! | t}} | ||
=== stricount === | === stricount === | ||
− | Example:<pre></pre> | + | Same as strcount, but case-insensitive. |
− | → | + | |
+ | Example: <pre>{{#stricount:This string sure has a lot of "T"'s in it! | t}}</pre> | ||
+ | → {{#stricount:This string sure has a lot of "T"'s in it! | t}} | ||
=== stripos === | === stripos === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== stristr === | === stristr === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strlen === | === strlen === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strpos === | === strpos === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strripos === | === strripos === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strrpos === | === strrpos === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strsplit === | === strsplit === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== strstr === | === strstr === | ||
− | Example:<pre></pre> | + | Example: <pre></pre> |
→ | → | ||
=== sha1 === | === sha1 === | ||
− | Example:<pre></pre> | + | Returns the [[wikipedia:sha1|sha1]] hash of the first parameter. |
− | → | + | |
+ | Example: <pre>{{#sha1:Dwarf Fortress}}</pre> | ||
+ | → {{#sha1:Dwarf Fortress}} | ||
=== md5 === | === md5 === | ||
− | Example:<pre></pre> | + | Returns the [[wikipedia:md5|md5]] hash of the first parameter. |
− | → | + | |
+ | Example: <pre>{{#md5:Dwarf Fortress}}</pre> | ||
+ | → {{#md5:Dwarf Fortress}} | ||
+ | |||
+ | === splitrand === | ||
+ | Splits a string and returns a random piece | ||
+ | |||
+ | Example: [[Main Page/Quote]] | ||
+ | |||
+ | == Math functions == | ||
=== randint === | === randint === | ||
− | Example:<pre></pre> | + | Returns a random integer between the two arguments provided. |
− | → | + | |
+ | Example: <pre>{{#randint:1|6}}</pre> | ||
+ | → {{#randint:1|6}} | ||
+ | |||
+ | <pre>{{#randint:6|1}}</pre> | ||
+ | → {{#randint:6|1}} | ||
+ | |||
+ | |||
+ | === ordinal === | ||
+ | <pre>{{#ordinal:1}}</pre> | ||
+ | → {{#ordinal:1}} | ||
+ | |||
+ | == Wikitext/utility functions == | ||
+ | |||
+ | === colorconvert === | ||
+ | Converts a color from one format to another. | ||
+ | |||
+ | Usage: | ||
+ | {{<nowiki/>#colorconvert: ''color'' | ''from_format'' | ''to_format'' }} | ||
+ | |||
+ | See {{tl|color scheme}} for an example. | ||
+ | Supported formats: | ||
+ | {| class="wikitable pre-table" | ||
+ | |- | ||
+ | ! format | ||
+ | ! example | ||
+ | ! result | ||
+ | |- | ||
+ | | <pre>rgb</pre> | ||
+ | | <pre>{{#colorconvert:rgb(255,128,12)|rgb|hex}}</pre> | ||
+ | | {{#tag:pre|{{#colorconvert:rgb(255,128,12)|rgb|hex}}}} | ||
+ | |- | ||
+ | | <pre>hex</pre> | ||
+ | | <pre>{{#colorconvert:#ff800c|hex|rgb}}</pre> | ||
+ | | {{#tag:pre|{{#colorconvert:#ff800c|hex|rgb}}}} | ||
+ | |- | ||
+ | | <pre>rgb1</pre>* | ||
+ | | <pre>{{#colorconvert:rgb(255,128,12)|rgb|rgb1}}</pre> | ||
+ | | {{#tag:pre|{{#colorconvert:rgb(255,128,12)|rgb|rgb1}}}} | ||
+ | |- | ||
+ | | <pre>rgb2</pre>* | ||
+ | | <pre>{{#colorconvert:rgb(255,128,12)|rgb|rgb2}}</pre> | ||
+ | | {{#tag:pre|{{#colorconvert:rgb(255,128,12)|rgb|rgb2}}}} | ||
+ | |- | ||
+ | | <pre>rgb3</pre>* | ||
+ | | <pre>{{#colorconvert:rgb(255,128,12)|rgb|rgb3}}</pre> | ||
+ | | {{#tag:pre|{{#colorconvert:rgb(255,128,12)|rgb|rgb3}}}} | ||
+ | |} | ||
+ | <nowiki/><small>*These can only be used as the third argument</small> | ||
=== param === | === param === | ||
− | Example:<pre></pre> | + | For use in templates: Returns the first parameter found from a list of parameter names, or the last argument if none were found. Intended to be easier to read than a chain of template default arguments. The following lines are equivalent: |
− | → | + | <pre> |
+ | {{{first|{{{2|{{{1|{{{last|None of the parameters were found}}}}}}}}}}}} | ||
+ | {{#param:first|2|1|last|None of the parameters were found}} | ||
+ | </pre> | ||
+ | |||
+ | Example: | ||
+ | |||
+ | "Template:Sample" contains: <pre>{{#param:first|2|1|last|None of the parameters were found}}</pre> | ||
+ | ---- | ||
+ | <pre>{{sample|first=text}}</pre> | ||
+ | → text | ||
+ | ---- | ||
+ | <pre>{{sample|text}}</pre> | ||
+ | → text | ||
+ | ---- | ||
+ | <pre>{{sample|foo|bar}}</pre> | ||
+ | → bar | ||
+ | ---- | ||
+ | <pre>{{sample|a|b|last=c|first=First!}}</pre> | ||
+ | → First! | ||
+ | ---- | ||
+ | <pre>{{sample|3=foo}}</pre> | ||
+ | → None of the parameters were found |
Latest revision as of 22:01, 31 August 2014
This page is not yet complete! |
Custom parser functions[edit]
String functions[edit]
char[edit]
Returns a CP437 character.
Example:
{{#char:1}}
→ ☺
strc[edit]
Expands backslash escape sequences, such as:
Text | Produces |
---|---|
\n | newline |
\t | tab |
Example:
Some example{{#strc:\t}}text
Produces:
Some example text
strcount[edit]
Returns the number of occurrences of the second parameter in the first parameter. Case-sensitive
Example:
{{#strcount:This string sure has a lot of "T"'s in it! | t}}
→ 3
stricount[edit]
Same as strcount, but case-insensitive.
Example:
{{#stricount:This string sure has a lot of "T"'s in it! | t}}
→ 5
stripos[edit]
Example:
→
stristr[edit]
Example:
→
strlen[edit]
Example:
→
strpos[edit]
Example:
→
strripos[edit]
Example:
→
strrpos[edit]
Example:
→
strsplit[edit]
Example:
→
strstr[edit]
Example:
→
sha1[edit]
Returns the sha1 hash of the first parameter.
Example:
{{#sha1:Dwarf Fortress}}
→ e71c8ec81bef5a3717cba2e82840b8bbdc6570d1
md5[edit]
Returns the md5 hash of the first parameter.
Example:
{{#md5:Dwarf Fortress}}
→ c5d1f740e7c056187c120083d2405a6a
splitrand[edit]
Splits a string and returns a random piece
Example: Main Page/Quote
Math functions[edit]
randint[edit]
Returns a random integer between the two arguments provided.
Example:
{{#randint:1|6}}
→ 6
{{#randint:6|1}}
→ 6
ordinal[edit]
{{#ordinal:1}}
→ 1st
Wikitext/utility functions[edit]
colorconvert[edit]
Converts a color from one format to another.
Usage:
{{#colorconvert: color | from_format | to_format }}
See {{color scheme}} for an example.
Supported formats:
format | example | result |
---|---|---|
rgb |
{{#colorconvert:rgb(255,128,12)|rgb|hex}} |
#ff800c |
hex |
{{#colorconvert:#ff800c|hex|rgb}} |
rgb(255, 128, 12) |
rgb1* |
{{#colorconvert:rgb(255,128,12)|rgb|rgb1}} |
255 |
rgb2* |
{{#colorconvert:rgb(255,128,12)|rgb|rgb2}} |
128 |
rgb3* |
{{#colorconvert:rgb(255,128,12)|rgb|rgb3}} |
12 |
*These can only be used as the third argument
param[edit]
For use in templates: Returns the first parameter found from a list of parameter names, or the last argument if none were found. Intended to be easier to read than a chain of template default arguments. The following lines are equivalent:
{{{first|{{{2|{{{1|{{{last|None of the parameters were found}}}}}}}}}}}} {{#param:first|2|1|last|None of the parameters were found}}
Example:
"Template:Sample" contains:
{{#param:first|2|1|last|None of the parameters were found}}
{{sample|first=text}}
→ text
{{sample|text}}
→ text
{{sample|foo|bar}}
→ bar
{{sample|a|b|last=c|first=First!}}
→ First!
{{sample|3=foo}}
→ None of the parameters were found