Difference between revisions of "WikiDB/Repeat tag syntax"

From TestWiki
Jump to: navigation, search
(Headers and footers: Let's demostrate a default value)
(Brought up to date and given a general overhaul.)
Line 5: Line 5:
 
  <repeat table="..." criteria="..." sort="...">Any old wiki text, with {{{variable}}} substitution.</repeat>
 
  <repeat table="..." criteria="..." sort="...">Any old wiki text, with {{{variable}}} substitution.</repeat>
  
The table attribute is required, and defines where the data comes from.  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 tag recognises the following attributes:
  
The criteria is optionalSpecifying this allows you to specify which records to returnOptions are currently ''very'' limited, partly due to limitations of passing in an attributeCurrently you can provide a comma-separated list of "field=value" or "field!=value" pairs, which are ANDed together.
+
; table (required)
 +
: This defines where the data comes from.  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.
 +
; criteria (optional)
 +
: Specifying this allows you to restrict the set of records that are displayedIf no criteria is specified, all rows are included.
 +
; sort (optional)
 +
: The rows are sorted by the fields in the order specifiedIf no sort is specified, then the sort order is undefined and may vary between page views.
  
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.
+
Full syntax for the criteria and sort attributes is the same as is used on the 'viewdata' tab to live-filter the data. See [[WikiDB/Querying data]] for full details. Note that, in the context of an HTML attribute, the <code>&lt;</code> character is not allowed, therefore you should use <code>LT</code> and <code>LTE</code> instead of <code>&lt;</code> and <code>&lt;=</code> in this context.
  
 
== Controlling the rendering ==
 
== Controlling the rendering ==

Revision as of 12:57, 31 March 2019

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 tag recognises the following attributes:

table (required)
This defines where the data comes from. 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.
criteria (optional)
Specifying this allows you to restrict the set of records that are displayed. If no criteria is specified, all rows are included.
sort (optional)
The rows are sorted by the fields in the order specified. If no sort is specified, then the sort order is undefined and may vary between page views.

Full syntax for the criteria and sort attributes is the same as is used on the 'viewdata' tab to live-filter the data. See WikiDB/Querying data for full details. Note that, in the context of an HTML attribute, the < character is not allowed, therefore you should use LT and LTE instead of < and <= in this context.

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|Unknown}}}<br>
|-
<footer>
|}
</footer>
</repeat>


Name Revenue
Intel Unknown
Microsof Seattle $8
Apple $7.42