|
Table of Contents
DekiScript can be used in page HTML and in XML extensions. With DekiScript you can generate dynamic HTML on the fly and embed real-time output into wiki pages.
The HTML attributes are used to dynamically convert the HTML content into a equivalent structure using DekiScript XML statements. The following example shows the complete set of HTML attributes and how they affect the initial <elem> element (note: HTML attributes can be applied to any HTML element, such <p>, <ul>, <table>, etc.).
Before
<elem init="initialization1" if="condition1" foreach="var variable in collection" where="condition2" block="initialization2">inner</elem>
After
<eval:block value="initialization1"> <eval:if test="condition1"> <eval:foreach var="variable" in="collection" where="condition2"> <eval:block value="initialization2"> <elem>inner</elem> </block> </eval:foreach> </eval:if> </eval:block>
If an attribute is missing then the corresponding DekiScript XML statement is omitted. For example the following HTML content uses the foreach attribute to show a list of files attached to the current page.
<ul>
<li foreach="var f in page.files">{{f.name}}</li>
</ul>
The HTML content is transformed into the following equivalent DekiScript XML content.
<ul>
<eval:foreach var="f" in="page.files">
<li>{{f.name}}</li>
</eval:foreach>
</ul>
DekiScript can also be used in XML extensions. The syntax is slightly more verbose and alleviates the need for special attributes on HTML elements.
This construct loops over the contents of a list or map. (Note: this construct replaces the earlier <eval:for> construct; <eval:foreach> requires v1.9.1 or later)
| Attribute | Type | Description |
| var | identifier | (optional) Name of the variable to initialize for each iteration. (default: $) |
| in | list/map | Expression resulting in a list or map value. |
| where | bool | (optional) Condition for determining if the current item should be included in the iteration. (default: true) |
Two additional variables are defined inside the foreach loop.
Example
<eval:foreach var="x" in="[1, 2, 3, 4, 5, 6]" where="x % 2 == 0"> <eval:expr value="x" /> is even.<br /> </eval:foreach>
This contruct select a conditional branch. (Note: <eval:if> requires v1.8.3 or later; <eval:elseif> and <eval:else> where require v1.9.1 or later)
| Attribute | Type | Description |
| test | bool | Condition for determining if the current item should be included in the iteration. (default: true) |
Example
<eval:if test="value < 0">Less than zero.</eval:if> <eval:elseif test="value > 0">Greater than zero.</eval:elseif> <eval:elseif test="value == 0">Value is zero</eval:elseif> <eval:else>Value is not a number.</eval:else>
Evaluates an expression and renders its result. (Note: the form with the 'value' attribute requires v1.9.1 or later)
| Attribute | Type | Description |
| value | any | (optional) Expression to render. (default: use text contents of element) |
Example 1
<eval:expr value="args.value" />
Example 2
<eval:expr>args.value</eval:expr>
Evaluates an expression and renders its result as a JavaScript value. This construct is a shorthand for <eval:expr>json.emit(expr)</eval:expr> or <eval:expr value="json.emit(expr)" />. (Note: the form with the 'value' attribute requires v1.9.1 or later)
| Attribute | Type | Description |
| value | any | (optional) Expression to render. (default: text contents of construct) |
Example 1
<eval:js value="args.value" />
Example 2
<eval:js>args.value</eval:js>
Evaluates an expression and scopes the result to the elemen. (Note: this contruct requires v8.05.1 or later)
| Attribute | Type | Description |
| value | any | Expression to evaluate. |
Example
<eval:scope value="var x = 1 + 2"> x has value <eval:expr value="x" /> </eval:scope>