Scripting

== If ==

~~~ xml
<if test="1+1==2">one plus one is two</if>
~~~

becomes

<if test="1+1==2">one plus one is two</if>
== Variables ==

<code lang="xml">
<def name="answer" value="4*10+2"/>
The answer is <value of="answer"/>.
</code>

becomes

<def name="answer" value="4*10+2"/>
The answer is <value of="answer"/>.

=== Predefined variables ===

* page_name: <value of="page_name"/>
* page_path: <value of="page_path"/>
* page_title: <value of="page_title"/>
* page_version: <value of="page_version"/>
* page_next_version: <value of="page_next_version"/>
* page_previous_version: <value of="page_previous_version"/>
* page_mime: <value of="page_mime"/>
* page_modified: <value of="page_modified"/>
== Functions ==

Functions can be defined with "def".

<code lang="xml">
<def name="fac" args="n">
  <if test="n>1">
    <call name="fac" n="n-1" result="m"/>
    <value of="n*int(m)"/>
  </if>
  <if test="n==1">1</if>
</def>

<call name="fac" n="20"/>
</code>

results in

<def name="fac" args="n">
  <if test="n>1">
    <call name="fac" n="n-1" result="m"/>
    <value of="n*int(m)"/>
  </if>
  <if test="n==1">1</if>
</def>

<call name="fac" n="20"/>

<code lang="xml">
<def name="fac2" args="n m">
  <if test="n==1"><value of="m"/></if>
  <if test="n>1"><call name="fac2" n="n-1" m="n*m"/></if>
</def>

<call name="fac2" n="20" m="1"/>
</code>

results in

<def name="fac" args="n">
  <if test="n>1">
    <call name="fac" n="n-1" result="m"/>
    <value of="n*int(m)"/>
  </if>
  <if test="n==1">1</if>
</def>

<call name="fac" n="20"/>

== Loops ==

Multiplication table:
<repeat times="10" counter="a">|=<value of="a"/></repeat>
<repeat times="10" counter="a">|=<value of="a"/>|<repeat times="9" counter="b"><value of="a*(b+1)"/>|</repeat>
</repeat>

Multiplication table #2:
<for from="1" to="10" counter="a">|=<value of="a"/></for>
<for from="1" to="10" counter="a">|=<value of="a"/>|<for from="2" to="10" counter="b"><value of="a*b"/>|</for>
</for>

Counter:
<repeat times="10" counter="n">* <value of="n"/>
</repeat>