Help:Widgets
From OiWiki
Contents |
Widgets Basics
All installed widgets can be seen at the Widgets category page. Each individual widget is a seperate page in the Widget namespace. Please refer to each one for specific instructions.
General Information on Using {{#widget}}
To add defined widget to pages, users can use {{#widget}} parser function. The syntax is as follows:
{{#widget:WidgetName|param1=value1|param2=value2}}
Where WidgetName is a page name in Widget namespace (e.g. Widget:WidgetName) and param=value pairs are defining parameters defined within widget code. See each individual Widget page for details on how to use them. Trust us, it really is much easier than it appears here.
Examples
YouTube
This widget allows you to add YouTube video player to your wiki page. To insert this widget, use the following code:
{{#widget:YouTube|id=XaSg6RCryYc}}
This will produce:
Technical Info
Arrays
If you use the same parameter multiple times, widget will get an array of values. You can use foreach to go through the array.
Booleans (true/false)
This extension supports passing boolean parameters by just using a parameter name without a value like this:
{{#widget:WidgetName|popup}}
This will set $popup to true for your widget. Also, in addition to PHP's default handling of boolean conversions, you can use value "false" to set boolean value false (this is not the case in PHP as string "false" doesn't get converted to boolean false, see PHP docs on boolean casting).
{{#widget:WidgetName|popup=false}}
Dotted notation
Parameter names can have dots and Smarty will interpret them as associative arrays so you can use foreach with both key and item attributes to traverse through them, or you can just use the same name with dots if you want to reference parameter directly.
Validate modifier
In addition to standard Smarty modifiers (like heavily used escape), Widgets extension implements validate modifier that uses PHP Data filtering to allow validating widget parameters.
To make sure $homepage variable value is a valid URL, you can use following code:
<a href="<!--{$homepage|validate:url}-->">Homepage</a>
Following values for the validate are supported (mapping to PHP's validation filters):
-
url(FILTER_VALIDATE_URL) -
int(FILTER_VALIDATE_INT) -
boolean(FILTER_VALIDATE_BOOLEAN) -
float(FILTER_VALIDATE_FLOAT) -
email(FILTER_VALIDATE_EMAIL) -
ip(FILTER_VALIDATE_IP)

