Get supplements (getSupplementRecords method) – Cordial Knowledge Base
How can we help?
Overview
The data stored within a supplement can be referenced and used within any message body.
Our example
For our example we'll be using supplement data consisting of a list of automobiles.
Using the tabs below you can view the HTML and Smarty used in the message, the supplement data being referenced (in JSON format) and the rendered output that will display when a message is sent or previewed.
Try it out
Download the sample data in .CSV format and use the API to upload into your system for testing.
{$supplement_records.key = 'automobiles'}
{$supplement_records.query = []}
{$supplement_records.limit = 25}
{$supplement_records.sort = []}
{$supplement_records.cacheMinutes = 25}
{$supplement_records.data = $utils->getSupplementRecords($supplement_records.key, $supplement_records.query, $supplement_records.limit, $supplement_records.sort, $supplement_records.cacheMinutes)}
{foreach $supplement_records.data as $array_position => $car}
<strong>({$array_position}) {$car.brand|capitalize} {$car.model|capitalize}</strong><br>
${$car.price}<br>
Mileage: {$car.mileage}<br><br>
{/foreach}
[
{
"model": "pilot",
"brand": "honda",
"price": 33000,
"mileage": 100000,
"id": "01"
},
{
"model": "explorer",
"brand": "ford",
"price": 34000,
"mileage": 39000,
"id": "02"
},
{
"model": "prius",
"brand": "toyota",
"price": 27000,
"mileage": 66000,
"id": "03"
},
{
"model": "model s",
"brand": "tesla",
"price": 130000,
"mileage": 56000,
"id": "04"
},
{
"model": "versa",
"brand": "nissan",
"price": 16000,
"mileage": 94000,
"id": "05"
},
{
"model": "camary",
"brand": "toyota",
"price": 29000,
"mileage": 310000,
"id": "06"
},
{
"model": "accord",
"brand": "honda",
"price": 24000,
"mileage": 49000,
"id": "07"
}
]
0. Honda Pilot
$33000
Mileage: 100000
1. Ford Explorer
$34000
Mileage: 39000
2. Toyota Prius
$27000
Mileage: 66000
3. Tesla Model S
$130000
Mileage: 56000
4. Nissan Versa
$16000
Mileage: 94000
5. Toyota Camary
$29000
Mileage: 310000
6. Honda Accord
$24000
Mileage: 49000
getSupplementRecords method
In order to access supplement data within a message, use the getSupplementRecords method, a custom extension of Smarty provided by Cordial.
The getSupplementRecords method has 5 parameters: key, query, limit, sort, and cacheMinutes. They must be written in this order and separated by commas. Only "key" is required. If you would like to leave a preceding parameter blank, it must be populated either by empty brackets "[]" for arrays or the word "null" for integers (empty single quotes should also work for integers).
getSupplementRecords($key, $query, $limit, $sort,$cacheMinutes)
| Parameters | Description | Required | Expected | Default |
|---|---|---|---|---|
| key | A unique key created by the user for a stored supplement. | Required | Valid key | NA |
| query | A filter used to limit the data set. Only indexed fields can be queried. | Optional | Array | [] |
| limit | A filter that sets a maximum number of records to return. | Optional | Integer | 25 |
| sort | Sort the order of the records returned. | Optional | Array | [] |
| cacheMinutes | Number of minutes to store the feed data in memory. | Optional | Integer | 0 |
Set the key
A unique key is created with each new supplement and is used to identify the supplement in the database.
You can retrieve the supplement key two ways:
- Via the UI by navigating to Data > Supplement Data
- Via the API by using the GET
/supplements call.
Example using the supplement "automobiles":
{$supplement_records.key = 'automobiles'}
{$supplement_records.data = $utils->getSupplementRecords($supplement_records.key)}
Set the query
In some cases, you may want to get specific records from the supplement. You can achieve this by adding query filters.
Only indexed fields within supplements can be used for query filters.