{at}

Looks a value up in a data set by a path of names and conditions - the @ notation as a tag.

Variables and stores Single tags

Syntax

{at 'field@store'}
{at "path.key='value'.field@store"}

Parameters

path
An @ expression: before the @ a dotted path - field names, and key='value' steps that pick the row whose field has that value - and after it where to look: a {data} store, a page array, a _data/ file or a level.

Description

{at 'path'} answers the value an @ expression points at - the same notation a field can carry, {$name@staff}, written as a tag with the path as a quoted parameter. The part after the @ says where to look: a data set made with {data}, an array of the page, a _data/ file, a stored sequence, or an enclosing level by name.

The part before the @ is a path through that data, its steps separated by dots. A plain step is a field name - owner.phone@shop descends into the owner object. A step id='b2' picks, among the rows at that point, the one whose id field is b2, so {at "id='b2'.name@staff"} is the name of the row with that id. Steps can be chained as deep as the data goes: {at "country.id='f0_162'.province.id='f0_17460'.name@mondial"}. A row can also be named by its key - 1.city@cities - and @globals searches the page's variables: {at 'order.total@globals'}. In a {data} set a bare field name searches the rows and answers the first one that has it.

The tag asserts its path: under the strict syntax check a path that reaches nothing - or an empty value - is an error naming the path. The field form ({$name@staff}) is searched more leniently, which is what optional lookups rest on. Use the lookup pipe to find one row by a key for every row of a loop.

Examples

Paths into nested data

Field names descend into objects; a key=value step picks the matching row.

Templateexamples/at/1-path.pad
{data 'atShop'}
{
  "name": "Corner Shop",
  "owner": { "name": "Eve", "phone": "555-0142" },
  "items": [
    { "sku": "k1", "title": "Kettle", "price": 24 },
    { "sku": "k2", "title": "Teapot", "price": 18 }
  ]
}
{/data}
<p>Owner: {at 'owner.name@atShop'}, phone {at 'owner.phone@atShop'}</p>
<p>Item k2: {at "items.sku='k2'.title@atShop"} at {at "items.sku='k2'.price@atShop"}</p>
Resultopen alone

Owner: Eve, phone 555-0142

Item k2: Teapot at 18

A row picked by its key

Among the rows of a data set, the one whose id matches answers its field.

Templateexamples/at/2-rows.pad
{data 'atStaff'}
[
  { "id": "a1", "name": "Ann", "city": "Oslo" },
  { "id": "b2", "name": "Bob", "city": "Rome" },
  { "id": "c3", "name": "Cleo", "city": "Lima" }
]
{/data}
<p>b2 is {at "id='b2'.name@atStaff"} from {at "id='b2'.city@atStaff"}.</p>
<p>The first city in the list: {at 'city@atStaff'}.</p>
Resultopen alone

b2 is Bob from Rome.

The first city in the list: Oslo.

See also

  • {data} Turns its content - JSON, XML, YAML, CSV, a list or a range - into a named data set for a later tag to iterate.
  • {set} Assigns one or more variables, as globals that outlive the level the tag stands in.
  • {tree} Renders a tree of rows: its body for every row, and {recurse} renders it again for the row's children.