Extension:Winter/Documentation/Winter v1

This is the language specification for Winter v1.0 - v1.5

Syntax
Winter functions follow a similar syntax to Wikipedia templates. The only difference is Winter functions are preceded by a #. The following is an example:

Like templates, whitespace surrounding the | character is ignored. However, unlike templates, you may also use quotation marks (") to demarcate a string. This is useful when you would like to end or begin a parameter with whitespace.  In the following example, param1 and param3 are equivalent.

After execution, the text of the function will be replaced with its return value. This allows for nesting of functions.

Commands that have a single parameter whose value is nothing can be written as

Commands that take parameters which do not contain white space can be written as

Variables, once defined, can be written as

#setvar
Variables are defined by the command setvar Syntax:

After execution, variable x would contain value.

#var
Syntax: #var would return value if the previous setvar command had been issued.

#var and #setvar also provide simple assignment arithmetic. Syntax:

Shortcut #var syntax
The following pairs are now equivalent, assuming foo has already been defined by a #setvar or #var command: =    =
 * This feature was added in v1.2

Variable names must meet the qualifications as a function name to use the shortcut syntax. For example: ---> valid ---> valid ---> not valid ---> valid

#unsetvar
Syntax: {{{#unsetvar| variable }}

Removes variable from the list of variables.

#isset
Syntax: Returns 1 if variable is set, otherwise returns 0

#if
Syntax:

If expression evaluates to 0, nothing (no space between | characters), or whitespace, it is considered false. Everything else is considered true. If expression is true, true statement is returned. If expression is false, false statement is returned. The third parameter may be omitted if nothing is to be returned if expression is false.

Logical comparisons using #op
Syntax:

#not
Syntax:

If param1 is true, returns 0, otherwise returns 1

#ifeq and #ifneq
Syntax

There are also two shortcut functions, ifeq and ifneq, to make common logic tests easier to type. The following pairs are equivalent

Loops
Please note that #while, #for, #repeat and #function use modified syntax: They require double pipes (||) in between parameters.

#while
Syntax: Media file link| expression || statement }}

Repeats and returns the statement as long as expression evaluates to true (ie, anything other than 0, nothing, or whitespace). expression is evaluated before statement is executed.

#for
Syntax:

Executes expr1, then repeats statement and exp3 until exp2 is not true.

#repeat
Syntax:

Repeats and returns the statement times times.

#function
Syntax:

A function, once defined, can be called just like any other function in Winter. Variables set inside a command block are local to the function, and the function cannot access the variables of the main script. To access the parameters of the function, use, , ..

Example:

returns foo123barABC

''Please note that #while, #for and #function use modified syntax.. they require double pipes (||) in between parameters.''

Arithmetic using #op
In 1.5.0 and higher, you may have any amount of operations. . The order of operations is from left to right.

operator can be any of the following:

#formula
Syntax:

formula is a string made up of values, operators, and parentheses. There must be whitespace on either side of all operators. The order of operations is parentheses, then left to right.

Valid formulas: 1 + 2             1 + ( 3 * 4 )      (1 + 2) - (3 + 4)

Invalid: 1+ 2 1 +( 3 + 4) (1+2)-(3+4)

Strings
Strings can be used in Winter without quotation marks. The first non-whitespace character after a pipe (|) is considered the beginning of the string, and the end of the string is the last non-white character before a pipe or closing double brace (}}).

If you would like to start or end the string with a whitespace, use a quotation marks. Quotation marks do not need to be matched.

Valid string syntax: => a == "This is a string" => a == "This is a string" => a == " This is a string" => a == "This is a string " => a == " This is a string "

The string functions are analogs of the php functions which share their names.

#substr
Syntax:

If no end is specified, will return to the end of the string. Negative values may be used.

#strpos
Syntax

Returns the position of the first occurence of needle in haystack. If needle doesn't occur in haystack, nothing will be returned (not even a space).

#str_replace
Syntax:

Replaces search with replace in string subject and returns the value

#strlen
Syntax:

Returns the length of the string

#preg_replace
Syntax:

Perform a regular expression search and replace. See [PHP's preg_replace] for more info

#nocache
Syntax:

Stops the generated output from being cached. This is useful for pages which must alway be generated when they are viewed, such as those that include time or date information or other dynamic content.

#define
Syntax:

Similar to the #DEFINE function in C, #define replaces all instances of text with macro. Unlike C macros, they can be defined anywhere and affect both output and program code. text and macro are not evaluated before being applied.

#default
Syntax:

Assigns template parameters (eg a default value.  This value will only be assigned if the parameter is not set when the template is called.

#urlvar
Syntax:

Returns the value of the variable defined in the url. For example, if a page was called like thisTemplate:nonexistent?var1=value1, value1 would be returned by:

#null
Syntax:

Executes the statement and returns NULL. Useful for executing commands without returning a value, or for text comments. If you wish stop a block of code from executing, use instead.

#noeval
Syntax:

Returns text, with the characters { | } converted to html entities (&amp;123; &amp;124; and &amp;125; respectively) which allows Winter code to be displayed without being evaluated. #noeval will stop at the first unmatched }} so if you wish to display invalid code you may need to use escape characters or html entities.

(#noeval was added in version 1.4.0, but is depreciated in 1.4.1 in favor of the &lt;nowinter> tag)

Escape Characters
The following escape characters may be used in any expression. They are evaluated after the expression is read but before it is parsed.

Version 1.4.0 and higher

Escape Char Equivalent --- -- ^!           | ^(           { ^)           } ^[            ^_           ^

Version 1.3 and lower

^^!         | ^^(          { ^^)          } ^^_          ^^

If used inside nested functions, you must escape the character for the level at which you want it to evaluate. For example:

returns | | |

&lt;nowinter>
Syntax: &lt;nowinter> &lt;/nowinter>

Text placed between &lt;nowinter> and &lt;/nowinter> will not be evaluated by Winter. The above code would display

(&lt;nowinter> added in version 1.4.1)