Content Rendering Engine
Insight Factory hosts content rendering engine. This engine is used to render dynamic content used in Insight Definition Content Templates.
Content Rendering Engine uses Stubble - a C# Mustache implementation - (https://github.com/StubbleOrg/Stubble).
Please note that not all of Stubble functionalities are supported (i.e. Stubble cases not described in this document might not work and their behaviour or lack of thereof is not considered a bug).
When defining Insight Definition Content Template, user can specify Data Model expressions containing dynamic values related to event, user, repositories and alias functions, e.g.
{
title: "Hi {{@e.user.name}}!"
description: "Last week you spent {{@r.MenigaPfmRepository.SumExpenses(since: c.Today - 7 * Day, category: 'FastFood' }} on fast-food. Can we interest you in a Gym Membership Subscription Pack?"
}
Please note that all dynamic content used in examples might not use correct available event data, alias functions or repos.
API
When creating dynamic content, please follow those rules:
- Each dynamic content section MUST start with correct token
{{@
and end with token}}
. - Each dynamic content list section MUST start with correct token
{{#
and end with token}}
. Dynamic content lists are only available for repositories. - Each dynamic content list MUST have mirroring end list tag that starts with
{{/
and ends with}}
. - Each dynamic content MUST be an expression, that could be used when defining Target Audience or Triggering Conditions part of creating Insight Definition.
- Each dynamic content CAN use each and any event property, alias functions and repositories, as long as they can also be used in this Insight Definition Triggering Condition or Target Audience section.
- The dynamic content model javascript object needs to passed as JSON to the API using
JSON.stringify(data)
Please call appropriate endpoints to obtain metadata of event properties, alias functions and repositories.
List rendering
It is possible to render lists. Start tag and end tag must be the same. Fields to use within list are limited to fields on list item, e.g.:
{
body: `You have made two payments related to the skiing:
{{#r.TransactionsRepository.Transactions.Where(x=>x.CategoryId == 262)}}
{{Amount}} {{Currency}}
{{/r.TransactionsRepository.Transactions.Where(x=>x.CategoryId == 262)}}`
}
Event data rendering
It is possible to render event data, e.g.:
{
title: "Your last transaction {{@e.text}}"
}
Repository data rendering
It is possible to render data from repositories or alias functions
{
description: "Your last transaction {{@e.text}} in category {{@r.MenigaPfm.GetCategoryName(e.category.id)}} was above monthly threshold {{@r.MenigaCashflowRepo.GetTreshold(e.category.id}}"
}
Multiline
It is possible to denote a new line using \n
character, e.g.
{
description: "Hi {{@e.user.name}} \n Your last credit card transaction above 500 EUR happened {{@e.transactionDate}}."
}