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

PropertyReturnsDescription
allEmojisList<Emoji>All emoji known to the emoji4j library, for use in emoji pickers.
allFieldBeansList<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.
allFieldsList<Field>All fields registered in the system, regardless of which content type or form they belong to.
componentHtmlTemplaterComponentHtmlTemplaterThe 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.

ParameterDescription
rootFolderthe 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.

ParameterDescription
templatethe source string containing zero or more KCode expressions
profilethe current user, may be null
varsa 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.

ParameterDescription
templatethe source string containing zero or more KCode expressions
profilethe current user, may be null
varsa map of variables available to the expressions, should include 'lead' and 'thisOrg' if appropriate
logslist 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.

ParameterDescription
inputHtmlthe HTML content containing dynamic components to evaluate
pagethe 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.

ParameterDescription
inputHtmlthe HTML content containing dynamic components to evaluate
paramsrequest parameters available to the components
varsa map of variables available to the components during evaluation
pagethe 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.

ParameterDescription
inputHtmlthe HTML content containing dynamic components to evaluate
profilethe profile to evaluate the components as
paramsrequest parameters available to the components
varsa map of variables available to the components during evaluation
pagethe 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.

ParameterDescription
templatethe MVEL template text to execute
pthe profile to evaluate the template as
localVarsan 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.

ParameterDescription
templatethe MVEL template text to execute
pthe profile to evaluate the template as
localVarsan optional map of variables to pass to the template
rfthe 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.

ParameterDescription
templatethe MVEL expression to evaluate
pthe profile to evaluate the expression as
localVarsa 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.

ParameterDescription
templatethe MVEL expression to evaluate
pthe profile to evaluate the expression as
localVarsa map of variables available to the expression
rfthe 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.

ParameterDescription
fieldIdthe id of the field to evaluate
leadthe 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.

ParameterDescription
fieldIdthe id of the field to evaluate
varsa 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.

ParameterDescription
fieldIdthe id of the field to evaluate
curUserthe user to evaluate the field as
varsa 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.

ParameterDescription
textthe 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.

ParameterDescription
templatePaththe 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.

ParameterDescription
templatePaththe template path to render, for example /theme/passwordResetEmail.html
contextParamsextra 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.

ParameterDescription
websiteoptional website to resolve the root folder from; if not provided, the current root folder is used
branchthe 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.

ParameterDescription
websitethe website whose menu is wanted
branchthe version of that website
userthe profile whose view of the menu to build, since visibility rules are per group; may be null for the anonymous visitor's view
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.