Registered as the "templatingManager" service, reachable from Velocity templates and GraalJS as services.templatingManager. Evaluates KCode field expressions and MVEL templates against a profile and a map of variables, renders dynamic components embedded in HTML, and generates HTML content from a template path either for the current request or standalone.
Group: Managers
Properties
| Property | Returns | Description |
|---|---|---|
| allEmojis | List<Emoji> | All emoji known to the emoji4j library, for use in emoji pickers. |
| allFieldBeans | List<FieldBean> | All fields registered in the system, as FieldBeans rather than raw Fields. Prefer this over getAllFields when inspecting the field catalogue, because a bean carries the parent types with subtype aliases already expanded - which is what decides whether one field can follow another in a kcode path. This is the same view the kcode picker is served. |
| allFields | List<Field> | All fields registered in the system, regardless of which content type or form they belong to. |
| componentHtmlTemplater | ComponentHtmlTemplater | The component templater used to render dynamic components for the current tenant's active theme. |
Methods
getComponentHtmlTemplater() · getAllFields() · getAllFieldBeans() · getAllFieldBeansForSite(RootFolder rootFolder) · evaluateAllFields(String template, Profile profile, Map vars) · evaluateAllFields(String template, Profile profile, Map vars, List<String> logs) · evaluateDynamicComponents(String inputHtml, Resource page) · evaluateDynamicComponents(String inputHtml, Map<String,String> params, Map<String,Object> vars, Resource page) · evaluateDynamicComponents(String inputHtml, Profile profile, Map<String,String> params, Map<String,Object> vars, Resource page) · executeMvelTemplate(String template, Profile p, Map localVars) · executeMvelTemplate(String template, Profile p, Map localVars, RootFolder rf) · executeMvelExpr(String template, Profile p, Map localVars) · executeMvelExpr(String template, Profile p, Map localVars, RootFolder rf) · evaluateField(String fieldId, Lead lead) · evaluateField(String fieldId, Map vars) · evaluateField(String fieldId, Profile curUser, Map vars) · getAllEmojis() · replaceEmojis(String text) · generateHtml(String templatePath) · generateHtml(String templatePath, Map<String,Object> contextParams) · invalidateRootMenuItemCache() · findAppTemplates(Website website, Branch branch) · findWebsiteMenu(Website website, Branch branch, Profile user)
getComponentHtmlTemplater()
Returns: ComponentHtmlTemplater
The component templater used to render dynamic components for the current tenant's active theme.
getAllFields()
Returns: List<Field>
All fields registered in the system, regardless of which content type or form they belong to.
getAllFieldBeans()
Returns: List<FieldBean>
All fields registered in the system, as FieldBeans rather than raw Fields. Prefer this over getAllFields when inspecting the field catalogue, because a bean carries the parent types with subtype aliases already expanded - which is what decides whether one field can follow another in a kcode path. This is the same view the kcode picker is served.
getAllFieldBeansForSite(RootFolder rootFolder)
Returns: List<FieldBean>
The fields available to a particular website, as FieldBeans. Use this rather than getAllFieldBeans whenever the website in question is not the one currently being served - a field only exists where the app contributing it is active, so the catalogue for one site is not the catalogue for another.
| Parameter | Description |
|---|---|
rootFolder | the root folder of the website to resolve fields for |
evaluateAllFields(String template, Profile profile, Map vars)
Returns: String
Evaluates all KCode field expressions embedded in the given string, replacing each one with its evaluated value.
| Parameter | Description |
|---|---|
template | the source string containing zero or more KCode expressions |
profile | the current user, may be null |
vars | a map of variables available to the expressions, such as lead or thisOrg |
evaluateAllFields(String template, Profile profile, Map vars, List<String> logs)
Returns: String
Evaluates all KCode field expressions embedded in the given string, replacing each one with its evaluated value, and captures any log output produced during evaluation.
| Parameter | Description |
|---|---|
template | the source string containing zero or more KCode expressions |
profile | the current user, may be null |
vars | a map of variables available to the expressions, should include 'lead' and 'thisOrg' if appropriate |
logs | list to which log lines produced during evaluation are appended |
evaluateDynamicComponents(String inputHtml, Resource page)
Returns: String
Evaluates dynamic components embedded in the given HTML, using the current request's parameters and no extra variables.
| Parameter | Description |
|---|---|
inputHtml | the HTML content containing dynamic components to evaluate |
page | the page resource the components are evaluated against |
evaluateDynamicComponents(String inputHtml, Map<String,String> params, Map<String,Object> vars, Resource page)
Returns: String
Evaluates dynamic components embedded in the given HTML, for the current user, with the given request parameters and variables.
| Parameter | Description |
|---|---|
inputHtml | the HTML content containing dynamic components to evaluate |
params | request parameters available to the components |
vars | a map of variables available to the components during evaluation |
page | the page resource the components are evaluated against |
evaluateDynamicComponents(String inputHtml, Profile profile, Map<String,String> params, Map<String,Object> vars, Resource page)
Returns: String
Evaluates dynamic components embedded in the given HTML for the given profile, with the given request parameters and variables, resolving the currently active apps for the current root folder.
| Parameter | Description |
|---|---|
inputHtml | the HTML content containing dynamic components to evaluate |
profile | the profile to evaluate the components as |
params | request parameters available to the components |
vars | a map of variables available to the components during evaluation |
page | the page resource the components are evaluated against |
executeMvelTemplate(String template, Profile p, Map localVars)
Returns: String
Executes an MVEL template for the current root folder, substituting expressions in the template with values evaluated against the given profile and variables.
| Parameter | Description |
|---|---|
template | the MVEL template text to execute |
p | the profile to evaluate the template as |
localVars | an optional map of variables to pass to the template |
executeMvelTemplate(String template, Profile p, Map localVars, RootFolder rf)
Returns: String
Executes an MVEL template for the given root folder, substituting expressions in the template with values evaluated against the given profile and variables. Use this overload outside of a request, where the current root folder cannot be resolved.
| Parameter | Description |
|---|---|
template | the MVEL template text to execute |
p | the profile to evaluate the template as |
localVars | an optional map of variables to pass to the template |
rf | the root folder to evaluate the template against |
executeMvelExpr(String template, Profile p, Map localVars)
Returns: Object
Evaluates a single MVEL expression for the current root folder, against the given profile and variables.
| Parameter | Description |
|---|---|
template | the MVEL expression to evaluate |
p | the profile to evaluate the expression as |
localVars | a map of variables available to the expression |
executeMvelExpr(String template, Profile p, Map localVars, RootFolder rf)
Returns: Object
Evaluates a single MVEL expression for the given root folder, against the given profile and variables. Use this overload outside of a request, where the current root folder cannot be resolved.
| Parameter | Description |
|---|---|
template | the MVEL expression to evaluate |
p | the profile to evaluate the expression as |
localVars | a map of variables available to the expression |
rf | the root folder to evaluate the expression against |
evaluateField(String fieldId, Lead lead)
Returns: Object
Evaluates a field for the given lead, making the lead available to the field's expression as the "lead" variable.
| Parameter | Description |
|---|---|
fieldId | the id of the field to evaluate |
lead | the lead to evaluate the field for, may be null |
evaluateField(String fieldId, Map vars)
Returns: Object
Evaluates a field for the current user, with the given variables available to its expression.
| Parameter | Description |
|---|---|
fieldId | the id of the field to evaluate |
vars | a map of variables available to the field's expression |
evaluateField(String fieldId, Profile curUser, Map vars)
Returns: Object
Evaluates a field for the given user, with the given variables available to its expression. If evaluation throws, the error message is returned as a bracketed string rather than propagating the exception.
| Parameter | Description |
|---|---|
fieldId | the id of the field to evaluate |
curUser | the user to evaluate the field as |
vars | a map of variables available to the field's expression, may be null |
getAllEmojis()
Returns: List<Emoji>
All emoji known to the emoji4j library, for use in emoji pickers.
replaceEmojis(String text)
Returns: String
Replaces emoji shortcode sequences in the given text, such as ":smile:", with their emoji characters.
| Parameter | Description |
|---|---|
text | the text to process |
generateHtml(String templatePath)
Returns: String
Generates HTML content by rendering the template at the given path for the current root folder, using the current request's parameters if there is one.
| Parameter | Description |
|---|---|
templatePath | the template path to render, for example /theme/passwordResetEmail.html |
generateHtml(String templatePath, Map<String,Object> contextParams)
Returns: String
Generates HTML content by rendering the template at the given path for the current root folder, with the given values made available in the Velocity context in addition to the current request's parameters, if there is one.
| Parameter | Description |
|---|---|
templatePath | the template path to render, for example /theme/passwordResetEmail.html |
contextParams | extra context values to pass to Velocity, may be null |
invalidateRootMenuItemCache()
Returns: void
Clears the cached root menu item for the current user and root folder, so the next request rebuilds the menu from scratch.
findAppTemplates(Website website, Branch branch)
Returns: Map<TemplatingApplication,List<TemplateDef>>
Finds all templates registered by the active apps in the given branch, grouped by the application that registered them.
| Parameter | Description |
|---|---|
website | optional website to resolve the root folder from; if not provided, the current root folder is used |
branch | the branch to find app templates for |
findWebsiteMenu(Website website, Branch branch, Profile user)
Returns: MenuItem
The navigation menu of one website version, as the merged tree a visitor would see: the items the active apps contribute, with the account's own /theme/menu.json customisation applied over them. <p> Given a website rather than read from the current context, because the menu is per website branch and a caller is usually asking about a site other than the one it is being served from - an admin tool, or an agent. Building it requires that website to be the current root folder, which is what this arranges; MenuManager.getRootMenuItem on its own would silently answer about whichever site happened to be current.
| Parameter | Description |
|---|---|
website | the website whose menu is wanted |
branch | the version of that website |
user | the profile whose view of the menu to build, since visibility rules are per group; may be null for the anonymous visitor's view |