v50 Steam/Premium information for editors
  • 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.
This notice may be cached—the current version can be found here.

Difference between revisions of "Help:Parser functions"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(→‎Wikitext/utility functions: forgot about colorconvert)
Line 2: Line 2:
 
= Custom parser functions =
 
= Custom parser functions =
 
== String functions ==
 
== String functions ==
 +
 +
=== char ===
 +
Returns a [[CP437]] character.
 +
 +
Example: <pre>{{#char:1}}</pre>
 +
&rarr; {{#char:1}}
 +
 
=== strc ===
 
=== strc ===
  

Revision as of 22:42, 20 February 2014

Custom parser functions

String functions

char

Returns a CP437 character.

Example:

{{#char:1}}

→ ☺

strc

Expands backslash escape sequences, such as:

Text Produces
\n newline
\t tab

Example:

Some example{{#strc:\t}}text

Produces:

Some example	text

strcount

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

Same as strcount, but case-insensitive.

Example:

{{#stricount:This string sure has a lot of "T"'s in it! | t}}

→ 5

stripos

Example:


stristr

Example:


strlen

Example:


strpos

Example:


strripos

Example:


strrpos

Example:


strsplit

Example:


strstr

Example:


sha1

Returns the sha1 hash of the first parameter.

Example:

{{#sha1:Dwarf Fortress}}

→ e71c8ec81bef5a3717cba2e82840b8bbdc6570d1

md5

Returns the md5 hash of the first parameter.

Example:

{{#md5:Dwarf Fortress}}

→ c5d1f740e7c056187c120083d2405a6a

splitrand

Splits a string and returns a random piece

Example: Main Page/Quote

Math functions

randint

Returns a random integer between the two arguments provided.

Example:

{{#randint:1|6}}

→ 5

{{#randint:6|1}}

→ 4

Wikitext/utility functions

colorconvert

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

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