TemplateRenderer

public protocol TemplateRenderer : ViewRenderer

Renders raw template data (bytes) to Views.

TemplateRenderers combine a generic TemplateParser with the TemplateSerializer class to serialize templates.

The TemplateRenderer is expected to provide a TemplateParser that parses its specific templating language. The templateFileEnding should also be unique to that templating language.

See each protocol requirement for more information.

  • render(_:_:userInfo:) Extension method

    Loads and renders a raw template at the supplied path.

    Declaration

    Swift

    public func render(_ path: String, _ context: TemplateData, userInfo: [AnyHashable: Any] = [:]) -> Future<View>

    Parameters

    path

    Path to file contianing raw template bytes.

    context

    TemplateData to expose as context to the template.

    userInfo

    User-defined storage.

    Return Value

    Future containing the rendered View.

  • render(template:_:userInfo:) Extension method

    Renders the template bytes into a view using the supplied Encodable object as context.

    Declaration

    Swift

    public func render<E>(template: Data, _ context: E, userInfo: [AnyHashable: Any] = [:]) -> Future<View> where E: Encodable

    Parameters

    template

    Raw template bytes.

    context

    Encodable item that will be encoded to TemplateData and used as template context.

    userInfo

    User-defined storage.

    Return Value

    Future containing the rendered View.

  • Renders template bytes into a view using the supplied context.

    Declaration

    Swift

    public func render(template: Data, _ context: TemplateData, file: String? = nil, userInfo: [AnyHashable: Any] = [:]) -> Future<View>

    Parameters

    template

    Raw template bytes.

    context

    TemplateData to expose as context to the template.

    file

    Template description, will be used for generating errors.

    userInfo

    User-defined storage.

    Return Value

    Future containing the rendered View.