mustache_expand_template Function

Syntax

C result = mustache_expand_template(C Template, C JSON)

Arguments

TemplateCharacter

The Mustache template string.

JSONCharacter

The JSON data to merge into the template.

Returns

resultCharacter

The resulting string after merging the data into the template.

Description

Expands a Mustache template by merging JSON data into the template.

Example

dim template as c = <<%str%
<h4>Product Info: {{name}}</h4>
<ul>
    <li>Product: {{name}}</li>
    <li>Colour: {{colour}}</li>
    <li>Price: ${{price}}</li>
</ul>
{{#inStock}}
<p>This item is currently in stock.</p>
{{/inStock}}
{{^inStock}}
<p>This item is out of stock.</p>
{{/inStock}}
%str%

dim json as c = <<%json%
{
    "name": "Widget X",
    "colour": "Blue",
    "price": 25.99,
    "inStock": true
}
%json%

dim txt as c = mustache_expand_template(template,json)