This example parses the products.csv file directly in the template by using the Expr expression language.
Name | Price | Category | Stock |
---|---|---|---|
Laptop | 1200 | Electronics | 15 |
Coffee Maker | 80 | Appliances | 30 |
Desk Chair | 250 | Furniture | 10 |
Notebook | 5 | Stationery | 100 |
Monitor | 300 | Electronics | 25 |
// the above is parsed with
let lines = split(csvData, "\n");
let header = map(split(trim(lines[0]), ","), { trim(#) });
let dataLines = filter(lines[1:], { trim(#) != "" });
map(dataLines, {
let fields = split(trim(#), ",");
let pairs = map(header, {
let value = fields[#index];
let isInt = value matches '^-?[0-9]+$';
let isFloat = value matches '^-?[0-9]+\\.[0-9]+$';
[#, isInt ? int(value) : (isFloat ? float(value) : value)]
});
fromPairs(pairs)
})
See the Expr documentation and language definition for more about the language.
Filtered products: electronics only ¶
This section only displays products with the category set to “Electronics”.
- Laptop - In stock: 15
- Monitor - In stock: 25