Allows content to be processed before any additional formatting is applied. Once processed other options such as cleansing, prefix, suffix are applied. Only fields with content are processed. This option should only be used on fields that do not update back to a data source, because there is no way of reversing the process. Ensure that preprocessing is stand-alone and not reliant on the formatted content of other fields as they may not exist at the point the script is called.
The following methods are built into EasyCatalog:
Lua
The content is passed as a ‘content’ variable and the return value is used as the new content. For example:
1 |
return string.format("<b>%s</b>", content) |
Mustache
Mustache is a logicless template engine for creating dynamic content from JSON fields.
A typical Mustache template:
1 2 3 4 5 6 |
Hello {{name}} You have just won {{value}} dollars! {{#in_ca}} Well, {{taxed_value}} dollars, after taxes. {{/in_ca}} |
1 2 3 4 5 6 7 |
{ "name": "Chris", "value": 10000, "taxed_value": 6000, "in_ca": true } |
1 2 3 4 |
Hello Chris You have just won 10000 dollars! Well, 6000.0 dollars, after taxes. |
JMESPath
JMESPath (JSON Matching Expression Paths) is a query language for search JSON. It allows you to declaratively extract elements from JSON. For example:
1 |
locations[?state == 'WA'].name | sort(@) | join(', ', @) |
1 2 3 4 5 6 7 8 |
{ "locations": [ {"name": "Seattle", "state": "WA"}, {"name": "New York", "state": "NY"}, {"name": "Bellevue", "state": "WA"}, {"name": "Olympia", "state": "WA"} ] } |
1 |
"Bellevue, Olympia, Seattle" |
XPath
XPath can be used to navigate through elements and attributes of an XML field. Given the following field content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="children"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="web"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> |
1 |
/bookstore/book[price>35.00]/title |
1 2 |
XQuery Kick Start Learning XML |