Help:Advanced functions

Jump to: navigation

Contents

Introduction

The advanced functions that are available include:

Parser Functions

see Wiki Parser Functions for full details

#expr:

computes a mathematical expression

Syntax:{{ #expr: expression }} 

#if:

Syntax:{{ #if: <condition> | <then text> | <else text> }}

If the condition is an empty string or consists only of whitespace, then it is considered false, and the else text is returned.

#ifeq:

Syntax:{{ #ifeq: <text 1> | <text 2> | <equal text> | <not equal text> }}

#ifexpr:

Syntax:{{ #ifexpr: <expression> | <then text> | <else text> }}

If the expression evaluates to zero this is false

#switch:

Syntax:{{ #switch: <comparison value>
| <value1> = <result1>
| <value2> = <result2>
| ...
| <valuen> = <resultn>
| <default result>
}}

String Functions

see Wiki String Functions for full details

#sub:

Substring function (from start to end of string if length empty)

Syntax:{{#sub:string|start|length}} 

#pos:

Position of key in string starting from offset(empty is 0)

Syntax:{{#pos:string|key|offset}}

#len:

Length of a string

Syntax:{{#len:string}}

#urlencode:

Make string URL code

Syntax:{{#urlencode:value}}

#urldecode:

Convert URL code to ASCII code

Syntax:{{#urldecode:value}}

#rpos:

Returns the last position of 'key' inside the given 'value', or -1 if the key is not found. Add +1 to the result to retrieve position after the last delimiter. This will also work when the delimiter is not found, because "-1 + 1" is zero.

Syntax:{{#rpos:value|key}}

#pad:

Padded 'value' to a total length with string 'with' in direction left, center or right.

Syntax:{{#pad:value|length|with|direction}}

#replace:

Returns the given value with all occurrences of 'from' replaced with 'to'.

Syntax:{{#replace:value|from|to}}

#explode:

Returns from input 'value' the 'nth string' created by splitting 'value' into strings at each occurrence of 'delimiter'.

Syntax:{{#explode:value|delimiter|nth string}}

Note: If the 'delimiter' is empty, which it should not be, the entire value is treated as one piece, instead of raising an error. So if as well the 'nth string' is zero, the entire value is returned untouched.

Replace Function

Removed as not necessary any longer.

Timeline

see Wiki Easy Timelines ...a lovely misnomer

Syntax:
<timeline>
ImageSize  = width:320 height:700
PlotArea   = right:40 top:10 left:40 bottom:10
DateFormat = yyyy
TimeAxis   = orientation:vertical order:reverse
Period     = from:-1500 till:2100
AlignBars  = early
ScaleMajor = unit:year increment:500 start:-1500
Colors     = 
  id:canvas value:rgb(1,1,0.85) 
BackgroundColors = canvas:canvas
PlotData =
  width:15 color:red
  bar:test from:-1500 till:43 # Ancient History
PlotData = 
  width:15 color:orange
  bar:test from:43 till:450 # Roman History
PlotData = 
  width:15 color:yellow
  bar:test from:450 till:1066 # Saxon History
PlotData = 
  width:15 color:green
  bar:test from:1066 till:1688 # English History
PlotData = 
  width:15 color:blue
  bar:test from:1688 till: # British History
PlotData = 
  bar:test at:43 mark:(line,white)
  at:43 shift:(10,0) text: Claudius Invades
  bar:test at:450 mark:(line,white)
  at:450 shift:(10,0) text: Hengest and Horsa given Thanet
  bar:test at:1066 mark:(line,white) 
  at:1066 shift:(10,0) text:William the Conqueror Invades
  bar:test at:1688 mark:(line,white) 
  at:1688 shift:(10,0) text:William III given Britain
</timeline>

Advanced template functions

These have been developed to deal with logic issues or replace PHP functions that are hard to maintain on migration and should work as long as above functions are implemented. They tend to use rather complex logic as wiki template language is not as English like as most programming languages !

Strip newlines

See Template:Strip newlines Removes line returns from text which can be useful when parsing text input by users and from the web

Syntax:{{Strip newlines|<input to be stripped of line returns in string>}}

PassEquals

see Template:PassEquals Allows the passing of an explicate link variable that contains equal signs "=" as an implicate variable. Will only work one deep so no good for nestled templates.

Syntax:{{PassEquals|link=<string to be passed> }}

Effectively only useful for a variable passed to a template that contains equal signs as many web links accessing databases do.

The syntax:{{UK|{{PassEquals|link=<pmid>17954520</pmid>}}}} works while {{UK|<pmid>17954520</pmid>}} fails due to generation of = signs.