Table of Contents

Interface ITemplateService

Namespace
ToSic.Sxc.Services
Assembly
ToSic.Sxc.dll

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 string

The source name, basically the first part of the token eg: [Name:Value]

values IDictionary<string, string>

Returns

ILookUp

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 string

The source name, basically the first part of the token eg: [Name:Value]

getter Func<string, string, string>

Returns

ILookUp

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 string

The 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

ILookUp

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 string

The source name, basically the first part of the token eg: [Name:Value]

item ICanBeEntity

An IEntity, ITypedItem or similar object.

protector NoParamOrder

see Convention: Named Parameters

dimensions string[]

optional array of languages to use when looking for the value - if the data is multi-language. Default to current languages.

Returns

ILookUp

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 string

The source name, basically the first part of the token eg: [Name:Value]

original ILookUp

Returns

ILookUp

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 NoParamOrder

see Convention: Named Parameters

sources IEnumerable<ILookUp>

optional additional sources

Returns

ITemplateEngine

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 NoParamOrder

see Convention: Named Parameters

sources IEnumerable<ILookUp>

optional sources, but without them this engine won't do much

Returns

ITemplateEngine

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 string
sources IEnumerable<ILookUp>

Returns

ILookUp

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 string
protector NoParamOrder
allowHtml bool
sources IEnumerable<ILookUp>

Returns

string