{[root]}
Description
Accesses the root object
If your use the {*root} command to, say, add a footer or header when using a JSON array as your data source, then this creates a root object that might look something like this:
var data = {
root: [
{firstname: 'Fred', lastname: 'Smith'},
{firstname: 'John', lastname: 'Jones'}
]
}{[root]} is a system object that refers to the data that is being expanded. With {[root]} you can use some javascript properties, like .length, to acquire information about the array. You can also use [root] to access elements in an array. For example, say you had this data set in the Template Tester:
[
{firstname: 'Fred', lastname: 'Smith'},
{firstname: 'John', lastname: 'Jones'},
{firstname: 'Ace', lastname: 'Rimmer'}
]You can create a root object in the template by using the {*root}{/*root} commands.
{*root}
{*header}There are people:{/*header}<br/>
{/*root}You can then use {[root][0].firstname} in the template to any access the firstname property in the first element of the root array.
{*root}
{*header}There are people {[root][0].firstname} :{/*header}<br/>
{/*root}The result:
There are people Fred :
Change the element to be [2] and the data will change accordingly:
{*root}
{*header}There are people {[root][2].firstname} :{/*header}<br/>
{/*root}Result:
There are people Ace :
In order to reference the last item in an array you can also use [-1]
{*root}
{*header}There are people {[root][-1].firstname} :{/*header}<br/>
{/*root}In this case the result will be the same.
There are people Ace :