Click or drag to resize

Template Class

A Template is a fragment or file used to build a localized string for various uses.

One of the most common uses for templates is as the basis for the body of an email message. To see an example of how to use a Template see IEmailService.

The most common format for a template is HTML, but, depending on how it is being used, any text format is supported. Templates support substitution markers whose name/value pairs are typically provided in a NameValueCollection when the template is resolved using one of the various Replace or Expand methods.

The markers may take two forms:

When populated from a IMapper default markers will, by default, be substitued using the DisplayText of the corresponding IField (obtained via DisplayTextGet(DispTextFlags)). However, an optional marker prefix may be included to specify otherwise (see TemplateNodeMarker). For example, {{&first_name}} would mean that the marker should be replaced with the HTML-escapted text for the "first_name" field's caption.

  • & - Caption: Use the field's Caption.
  • * - RawValue: Use the field raw value.
  • + - ImmediateEdit: Substitute for use with ImmediateEdit. This only applies to page content, but not to email templates and similar.
  • / - NavLink: Substitute with a field's NavLink. NavLink marks should not be escaped (that is, always use the '[[]]' delimiters).
  • % - Template: Substitute with the expanded content of the specified inner template. Template marks should generally not be escaped (that is, generally use the '[[]]' delimiters). A template marker may optionally include a set of name/value pairs used in expanding the inner template. Any name/value pairs provided will override the corresponding of name/value pairs provided to the outer template. The syntax for a template reference is %<template-name>[:name1=value1;name2=value2...] (wrapped in an outer [[]] or {{}}). A colon is used to separate the optional name/value list, a semi-color separates each name/value pair, and an equals sign separates each name from its value.
  • # - Numeric: Substitute with a numeric field's raw value or 0 (zero) when null/empty.
  • = - HasValue: Substitute with "1" or "" (empty string) depending on whether or not the field's DisplayText has a non-null/non-blank value.

Templates are commonly used for the following purposes:

Templates also support events fired to TemplateExtensionBase components:

Examples
Here is an example of a simple email template including substituion markers:
Dear {{first_name}} {{last_name}},
<br />
Thank you contacting us regarding interest in our {{product_name}} product.  One of our sales people will contact
you shortly to help you with any questions you may have and to aid in ordering.
<br />
Additional information is available at [[product_url]].
<br />
Sincerely,
<br />
{{company_name}}
Inheritance Hierarchy
SystemObject
  NetQuarryTemplate

Namespace:  NetQuarry
Assembly:  EAP.Core (in EAP.Core.dll) Version: 2.0.0.0 (4.6.8.0)
Syntax
[SerializableAttribute]
public class Template : ICloneable, IEAPBase

The Template type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyAttributes
Get the TemplateAttrs for this Template.
Public propertyCategory
Gets the Template's category.
Public propertyFileID
Gets the Template's file id for templates that aren't stored locally.
Public propertyFilePath
Gets the path to the template file, if any. Note that certain TemplateAttrs affect how this property is interpreted.
Public propertyID
Gets the Template's ID.
Public propertyName
Gets's the Template's name.
Public propertyPriority
Gets the Template priority. When a user has access to multiple Templates with the same Name, the accessible Template with the highest Priority number is favored.
Public propertyProperties
The Properties collection for the object.
Public propertyTemplateFields
Returns the Template's TemplateFields collection of TemplateField objects.
Public propertyTemplateType
Gets the Template type.
Public propertyTextItems
The localized TextItems collection for the object.
Top
Methods
  NameDescription
Public methodClone
Returns a MemberwiseClone copy of this object.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExpand(IAppContext, NameValueCollection, String, String, String)
Public methodExpand(IAppContext, NameValueCollection, ContentResolution, String, String, String)
Expands the template using the nameValues.
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFireEvent
Fires the specified ExtensionEvents against the template's extensions. See TemplateExtensionBase for information about available template events.
Public methodGetExpandedBody
Public methodGetExpandedSubject
Returns the subject expanded with the items from the nameValues
Public methodGetFieldList(ContentResolution) Obsolete.
Gets a semi-colon-separated field list appropriate for use as an IncludeFields string. Note this method is deprecated in favor of GetFieldList(IAppContext, ContentResolution, TemplateReplaceFlags) because an IAppContext is required in order to include any inner template fields (see Template.
Public methodGetFieldList(IAppContext, ContentResolution, TemplateReplaceFlags)
Gets a semi-colon-separated field list appropriate for use as an IncludeFields string.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetTemplateNodes
Gets the collection of TemplateNode objects describing this template. The collection will be loaded if it has not yet been loaded.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReplace(NameValueCollection)
Replaces the named tags in the document with the values in the NameValueCollection. Note that this overload does not support embedded function resolution. Use the Replace(IAppContext, NameValueCollection, ContentResolution, TemplateReplaceFlags) overload if embedded function resolution is desired.
Public methodReplace(NameValueCollection, ContentResolution)
Replaces the named tags in the document with the values in the NameValueCollection. Note that this overload does not support embedded function resolution. Use the Replace(IAppContext, NameValueCollection, ContentResolution, TemplateReplaceFlags) overload if embedded function resolution is desired.
Public methodReplace(NameValueCollection, ContentResolution, TemplateReplaceFlags)
Replaces the named tags in the document with the values in the NameValueCollection. Note that this overload does not support embedded function resolution. Use the Replace(IAppContext, NameValueCollection, ContentResolution, TemplateReplaceFlags) overload if embedded function resolution is desired.
Public methodReplace(IAppContext, NameValueCollection, ContentResolution, TemplateReplaceFlags)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Public methodUsesNodeBasedExpansion
Gets whether or not this template uses the new node-based template expansion. To enable node-based expansion system-wide, set the UseNodeBasedTemplateExpansionCompatibility feature. To enable it for a particular template only set the template's UseNewTemplateExpansion attribute.
Top
Extension Methods
  NameDescription
Public Extension MethodEqualValue
Determines if the object value is equal to another object. If the two objects are null, then this returns true. There is special handling for guid comparisons (since a guid could be a string formatted in up to 3 different ways). If the special guid handling is not performed, then the object.Equals method is used.
(Defined by EAPUtil.)
Top
See Also