Difference between revisions of "WikiDB/Repeat tag syntax"

From TestWiki
Jump to: navigation, search
(moved WikiDB/Repeat tag syntax to WikiDB/Repeat tag syntax/Archive: Archiving - the new syntax has been implemented.)
 
(Moved from WikiDB/Syntax, and expanded to include new header/footer elements)
Line 1: Line 1:
#REDIRECT [[WikiDB/Repeat tag syntax/Archive]]
+
<small>See [[WikiDB/Repeat tag syntax/Archive]] for old development discussion.</small>
 +
 
 +
The '''&lt;repeat&gt;''' tag allows you to query the data.
 +
 
 +
&lt;repeat table="..." criteria="..." sort="...">Any old wiki text, with {{{variable}}} substitution.&lt;/repeat>
 +
 
 +
The table attribute is required, and defines where the data comes from.  Again, the table does not need to be defined on the wiki - the tag will pull data for all rows that specified this table, even if the table does not exist.
 +
 
 +
The criteria is optional.  Specifying this allows you to specify which records to return.  Options are currently ''very'' limited, partly due to limitations of passing in an attribute.  Currently you can provide a comma-separated list of "field=value" or "field!=value" pairs, which are ANDed together.
 +
 
 +
The sort contains a comma separated list of fields with an optional 'DESC' modifier (e.g. "Field1,Field2 DESC,Field3").  The rows are sorted by the fields in the order specified.
 +
 
 +
== Controlling the rendering ==
 +
 
 +
There are currently two ways for the results of the query to be rendered:
 +
 
 +
* If the repeat tag is empty (or just contains white-space) then WikiDB will output the data as a table, in a standard format.
 +
* If the repeat tag contains any text, then this will be repeated for each row returned by the query.  Any field name inside three curly brackets (e.g. <code><nowiki>{{{FieldName}}}</nowiki></code>) will be replaced by the value of the field for the current row, and the result will be parsed as wiki text.  Field aliases are resolved correctly, so if you defined 'name' as an alias for 'first name' then using either field will give the same result.
 +
 
 +
=== Headers and footers ===
 +
 
 +
It is possible to specify a header and/or footer section within your repeat tag, and if present these are output before/after the individual rows.  For most use-cases you could achieve the same result by putting the header/footer content outside the tag, but due to the way MediaWiki rendering works it is not possible to do this if you want to output a table.  To output a custom table, you will need to open it in your header section and close it in your footer, like this:
 +
 
 +
<pre>
 +
<repeat Table="Companies3">
 +
<header>
 +
{| class="wikitable"
 +
! Name !! Revenue
 +
|-
 +
</header>
 +
| '''{{{Name}}}''' <small>{{{Location}}}</small> || {{{Revenue}}}<br>
 +
|-
 +
<footer>
 +
|}
 +
</footer>
 +
</repeat>
 +
</pre>
 +
 
 +
<repeat Table="Companies3">
 +
<header>
 +
{| class="wikitable"
 +
! Name !! Revenue
 +
|-
 +
</header>
 +
| '''{{{Name}}}''' <small>{{{Location}}}</small> || {{{Revenue}}}<br>
 +
|-
 +
<footer>
 +
|}
 +
</footer>
 +
</repeat>

Revision as of 00:25, 17 March 2013

See WikiDB/Repeat tag syntax/Archive for old development discussion.

The <repeat> tag allows you to query the data.

<repeat table="..." criteria="..." sort="...">Any old wiki text, with {{{variable}}} substitution.</repeat>

The table attribute is required, and defines where the data comes from. Again, the table does not need to be defined on the wiki - the tag will pull data for all rows that specified this table, even if the table does not exist.

The criteria is optional. Specifying this allows you to specify which records to return. Options are currently very limited, partly due to limitations of passing in an attribute. Currently you can provide a comma-separated list of "field=value" or "field!=value" pairs, which are ANDed together.

The sort contains a comma separated list of fields with an optional 'DESC' modifier (e.g. "Field1,Field2 DESC,Field3"). The rows are sorted by the fields in the order specified.

Controlling the rendering

There are currently two ways for the results of the query to be rendered:

  • If the repeat tag is empty (or just contains white-space) then WikiDB will output the data as a table, in a standard format.
  • If the repeat tag contains any text, then this will be repeated for each row returned by the query. Any field name inside three curly brackets (e.g. {{{FieldName}}}) will be replaced by the value of the field for the current row, and the result will be parsed as wiki text. Field aliases are resolved correctly, so if you defined 'name' as an alias for 'first name' then using either field will give the same result.

Headers and footers

It is possible to specify a header and/or footer section within your repeat tag, and if present these are output before/after the individual rows. For most use-cases you could achieve the same result by putting the header/footer content outside the tag, but due to the way MediaWiki rendering works it is not possible to do this if you want to output a table. To output a custom table, you will need to open it in your header section and close it in your footer, like this:

<repeat Table="Companies3">
<header>
{| class="wikitable"
! Name !! Revenue
|-
</header>
| '''{{{Name}}}''' <small>{{{Location}}}</small> || {{{Revenue}}}<br>
|-
<footer>
|}
</footer>
</repeat>


Name Revenue
Intel
Microsof Seattle $8
Apple $7.42