Help:Widget syntax

Widget page syntax
The Widgets extension uses the Smarty PHP templating engine to provide simple templating functionality within widget pages. All parameters passed to a widget are converted into Smarty parameters.

Important: Use escape modifiers on all passed-in parameters to prevent users from passing in raw HTML from normal wiki pages. Failure to protect against this will expose the hosting site to XSS (and other) attacks.

Arrays
If you use the same parameter multiple times, the widget will get an array of values. You can use to go through the array.

Booleans (true/false)
Since version 0.8.5, this extension supports passing boolean parameters by just using a parameter name without a value, like this:

This will set  to   for your widget. Also, in addition to PHP's default handling of boolean conversions, you can use value "false" to set the boolean value  (this is not the case in PHP as string "false" doesn't get converted to a boolean false; see PHP docs on boolean casting).

Dotted notation
Parameter names can have dots, and Smarty will interpret them as associative arrays, so you can use with both   and   attributes to traverse through them, or you can just use the same name with dots if you want to reference the parameter directly.

Validate modifier
In addition to standard Smarty modifiers (like the heavily used ), the Widgets extension implements the   modifier, that uses PHP Data filtering to allow for validating widget parameters.

To make sure the  variable value is a valid URL, you can use following code: Homepage

The following values for the validate are supported (mapping to PHP's validation filters):
 * (FILTER_VALIDATE_URL)
 * (FILTER_VALIDATE_INT)
 * (FILTER_VALIDATE_BOOLEAN)
 * (FILTER_VALIDATE_FLOAT)
 * (FILTER_VALIDATE_EMAIL)
 * (FILTER_VALIDATE_IP)

Refreshing a widget page
If you're using a call to the widget within the widget page itself, then you will not see the updated widget (and no widget at all when you just created a page). This happens because the page contents are not available to the Widgets extension until a page is saved, but the call to the  parser function is made before the page is saved. After the page is saved, it's cached by MediaWiki, so you won't see the result even if you reload the page via the browser. To make the latest edits to the widget code appear, you need to refresh the page in the cache; to do this, you just need to use the  action (see also Purge extension), or wait a certain amount of time (up to 24 hours).

Widgets and ParserFunctions
Using ParserFunctions within templates to display widgets, makes them an invaluable tool for creating complex displays of data with minimal lines of code.

It is particularly helpful if you want to pre-set some parameters of the widget while allowing users to modify others (e.g. video ID for YouTube widget or user handle for Twitter widget).

Simply including a widget in existing template that collects necessary data might be an easy way to enhance existing site without additional content work.