Scriban Email Workflow Action - WeTeam/WeBlog GitHub Wiki

From the early versions of WeBlog, WeBlog has included a workflow email action which uses the NVelocity templating language. The use of NVelocity was limited within Sitecore, so the library was deprecated and finally removed in Sitecore 9.3.

Starting with WeBlog 4.0, WeBlog for Sitecore 9.0 and later include a new workflow email action which uses the Scriban templating language for the fields of the email. This is the same templating language used by Sitecore Experience Accelerator (SXA).

Refer to the /sitecore/system/Workflows/WeBlog Comments/Created/Submit/Email Entry Author - Scriban item to see the workflow action in action.

Scriban Example

Scriban is similar in style to Liquid templates. It uses double curly braces {{ }} to define script blocks which can be used to output the value of context variables and execute code.

{{blog.title.raw}} just got a new comment from {{comment.author_name}}

Default Context Variables

The following variables are added to the Scriban context and made available to the Scriban template when the action is invoked:

Variable Name Type Comment
time System.DateTime The current date and time
args Sitecore.Workflows.Simple.WorkflowPipelineArgs The arguments of the current workflow invocation
item Sitecore.Data.Items.Item The item traversing the workflow
actionItem Sitecore.Data.Items.ProcessorItem The workflow action item being invoked
history Sitecore.Workflows.WorkflowEvent[] The workflow history for the item traversing the workflow
state Sitecore.Workflows.WorkflowState The workflow state the item is in
nextState Sitecore.Data.Items.Item The definition item for the next workflow state the item is traversing to
user Sitecore.Security.Accounts.User The current user from the Sitecore context
site Sitecore.Sites.SiteContext The current site from the Sitecore context
entry Sitecore.Modules.WeBlog.Data.Items.EntryItem The closest WeBlog entry item to the item traversing the workflow
entryCreatedBy Sitecore.Security.UserProfile The user profile of the user that created the entry item
entryUpdatedBy Sitecore.Security.UserProfile The user profile of the user that updated the entry item
comment Sitecore.Modules.WeBlog.Data.Items.CommentItem The comment item, if the item traversing the workflow is a WeBlog comment
blog Sitecore.Modules.WeBlog.Data.Items.BlogHomeItem The blog under which the item traversing the workflow exists

Using the Email Action

To add the email action to an existing workflow, under a workflow state or command, add an item based on the /sitecore/temapltes/Modules/WeBlog/Scriban Mail Action template.

Populate the To, From, Subject and Message fields, either with plain text, or with Scriban templates.

Using the Context Variables

Context variables can be used directly in the Scriban template:

{{time}}

To use the property of a variable, use dot notation:

{{entryUpdatedBy.email}}

Scriban does some member renaming to make the syntax more like Liquid. As you can see in the example above, the Email property of the UserProfile has been renamed to use all lowercase letters. In addition, if the property contains multiple words, the renamed property will separate the words with underscores:

{{comment.author_name}}

Extending the Context Variables

The email action uses the weblogPopulateScribanMailActionModel pipeline to populate context variables. The pipeline is defined in the App_Config\Include\WeBlog.ScribanMailAction.config file. To add additional variables to the context, add you own processor to this pipeline. The processor's Process method must accept arguments of type Sitecore.Modules.WeBlog.Pipelines.PopulateScribanMailActionModel.PopulateScribanMailActionModelArgs.

Use the methods of PopulateScribanMailActionModelArgs to manage the variables that will be added to the Scriban context.

Method Name Purpose
AddModel Adds a variable to the context
RemoveModel Remove a variable from the context
ModelContains Checks to see if a variable has already been added to the context
GetModel Retrieves a previously added variable, or retrieves the entire context