Template Attributes



Summary

Template Attributes allow administrators to use the Razor templating language to construct dynamic text or hyperlinks. They are also often used to calculate values based on client-specific business rules which are then used as inputs to other pieces of configuration.

See also: Template DO's and DONT's



Overview

Template Attributes allow administrators to use the Razor templating language to construct dynamic text or hyperlinks. They are also often used to calculate values based on client-specific business rules which are then used as inputs to other pieces of configuration.





Attributes

To access Workflow Attributes in a Template, use the Model.<Entity> syntax, which is sometimes called "entity-scoped syntax".

For instance, to access an Attribute belonging to the Activity Instance entity, you would do:

@Model.ActivityInstance.AttributeName





"Attributes" properties

Workflow Attribute values are exposed via the Attributes keyword in a Template.

The template editor displays a list of known values, and values can be mocked out in preview mode.



WorkflowTemplateRenderModel

Model.Environment = the environment string ("DEV", "PROD", etc) applied to the current configuration



"Model" properties

These elements are accessed as Model in a Template. They come from WorkflowTemplateRenderModel.

They are NOT exposed in the sidebar of available attributes and cannot be mocked out in preview mode.



Extensions

SourceAddressAttribute.GetDistanceTo(TargetAddressAttribute, DistanceUnit.Miles) - Distance between two Validated Address Attributes (with Latitude and Longitude values)

Uses System.Device.Location.GeoCoordinate to make the distance calculation

Sample Template
@using Heuristics.LearningBuilder.WorkflowAttributes @DistanceFrom() @functions { public string DistanceFrom() { try { var address1 = Model.MemberRole.GetAttribute<AddressAttribute>("Address_1"); var address2 = Model.MemberRole.GetAttribute<AddressAttribute>("Address_2"); if (address1 == null || address2 == null || address1.AddressId == 0 || address2.AddressId == 0) { return string.Empty; } return address1.GetDistanceTo(address2, DistanceUnit.Miles).ToString("N2") + " miles"; } catch(Exception a) { return a.Message; } } }







Related articles