datasource

Fetch an entry from a data source

Definition

object datasource(string $dataSourceName, string $column, string $lookFor)

Gets the first object from $dataSourceName whose value of $column is equal to $lookFor.

Parameters

string $dataSourceName

Name of the data source to use.

string $column

Name of the column to search.

string $lookFor

The string value to look for in $column.

Returns

object

The first object in $dataSourceName whose value of $column in equal to $lookFor.

Examples

Example data source in table view.

ExampleDataSource in table view.

[
  {"id" : 0, "name" : "Julia", "age" : 30},
  {"id" : 1, "name" : "Alexander", "age" : 57}, 
  {"id" : 2, "name" : "Pete", "age" : 71}, 
  {"id" : 3, "name" : "Selma", "age" : 42}
]
{
  julia: datasource('ExampleDataSource', 'name', 'Julia'),
  alexanderAge: datasource('ExampleDataSource', 'name', 'Alexander').age,
  alex: datasource('ExampleDataSource', 'name', 'Alex'),
  nameOf30YearOld: datasource('ExampleDataSource', 'age', '30').name,
  number57YearOld: datasource('ExampleDataSource', 'id', `57`)
}
{
  "julia": {"id": 0, "name": "Julia", "age": "30"},
  "alexanderAge": 57,
  "alex": null,
  "nameOf30YearOld": "Julia",
  "number57YearOld": null
}

See also

  • datasource_many, a similar function that returns an array of all objects that match a certain value.