Interface ITemplateService
Service to help parse token-based templates.
[PublicApi]
public interface ITemplateService
Remarks
Released in 18.03
Methods
CreateSource(string, IDictionary<string, string>)
Create a source based on a dictionary. Lookup will be case-insensitive.
ILookUp CreateSource(string name, IDictionary<string, string> values)
Parameters
name
stringThe source name, basically the first part of the token eg: [Name:Value]
values
IDictionary<string, string>
Returns
CreateSource(string, Func<string, string, string>)
Create a source using a function, basically a very custom source. This variant has 2 string parameters - the key and the format-string.
ILookUp CreateSource(string name, Func<string, string, string> getter)
Parameters
name
stringThe source name, basically the first part of the token eg: [Name:Value]
getter
Func<string, string, string>
Returns
CreateSource(string, Func<string, string>)
Create a source using a function, basically a very custom source.
ILookUp CreateSource(string name, Func<string, string> getter)
Parameters
name
stringThe source name, basically the first part of the token eg: [Name:Value]
getter
Func<string, string>The function which uses the key to retrieve a value. It will be case-sensitive/-insensitive based on your code.
Returns
CreateSource(string, ICanBeEntity, NoParamOrder, string[])
Create a source using an entity (or entity-like thing such as an ITypedItem) as the source.
ILookUp CreateSource(string name, ICanBeEntity item, NoParamOrder protector = default, string[] dimensions = null)
Parameters
name
stringThe source name, basically the first part of the token eg: [Name:Value]
item
ICanBeEntityAn IEntity, ITypedItem or similar object.
protector
NoParamOrderdimensions
string[]optional array of languages to use when looking for the value - if the data is multi-language. Default to current languages.
Returns
CreateSource(string, ILookUp)
Create a source based on another source. This is mainly used to give a source another name.
ILookUp CreateSource(string name, ILookUp original)
Parameters
name
stringThe source name, basically the first part of the token eg: [Name:Value]
original
ILookUp
Returns
Default(NoParamOrder, IEnumerable<ILookUp>)
Start with the default engine, which already has lookups for QueryString and similar sources.
ITemplateEngine Default(NoParamOrder protector = default, IEnumerable<ILookUp> sources = null)
Parameters
protector
NoParamOrdersources
IEnumerable<ILookUp>optional additional sources
Returns
Empty(NoParamOrder, IEnumerable<ILookUp>)
Start with an empty engine. This usually only makes sense, if you provide custom sources.
ITemplateEngine Empty(NoParamOrder protector = default, IEnumerable<ILookUp> sources = null)
Parameters
protector
NoParamOrdersources
IEnumerable<ILookUp>optional sources, but without them this engine won't do much
Returns
GetSource(string)
Get a built-in source by name. This is usually used when you want to create a template-engine with some specific sources, and you explicitly need for example the QueryString source as well.
ILookUp GetSource(string name)
Parameters
name
string
Returns
- ILookUp
The source if found, otherwise null
MergeSources(string, IEnumerable<ILookUp>)
Merge multiple sources into one.
ILookUp MergeSources(string name, IEnumerable<ILookUp> sources)
Parameters
name
stringsources
IEnumerable<ILookUp>
Returns
Remarks
Added v17.09
Parse(string, NoParamOrder, bool, IEnumerable<ILookUp>)
Quick parse a template using the default engine, and optional sources.
string Parse(string template, NoParamOrder protector = default, bool allowHtml = false, IEnumerable<ILookUp> sources = null)
Parameters
template
stringprotector
NoParamOrderallowHtml
boolsources
IEnumerable<ILookUp>