TemplateEngine

public protocol TemplateEngine

Template Engine protocol for Kitura. Implemented by Templating Engines in order to integrate with Kitura’s content generation APIs.

  • The file extension of files in the views directory that will be rendered by a particular templating engine.

    Declaration

    Swift

    var fileExtension: String { get }
  • Take a template file and a set of “variables” in the form of a context and generate content to be sent back to the client.

    Declaration

    Swift

    func render(filePath: String, context: [String : Any]) throws -> String

    Parameters

    filePath

    The path of the template file to use when generating the content.

    context

    A set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.

  • render(filePath:context:options:) Default implementation

    Take a template file and a set of “variables” in the form of a context and generate content to be sent back to the client.

    Default Implementation

    Declaration

    Swift

    func render(filePath: String, context: [String: Any],
                options: RenderingOptions) throws -> String

    Parameters

    filePath

    The path of the template file to use when generating the content.

    context

    A set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.

    options

    rendering options, different per each template engine

  • Take a template file and a set of “variables” in the form of a context and generate content to be sent back to the client.

    Default Implementation

    Declaration

    Swift

    func render(filePath: String, context: [String: Any],
                options: RenderingOptions, templateName: String) throws -> String

    Parameters

    filePath

    The path of the template file to use when generating the content.

    context

    A set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.

    options

    rendering options, different per each template engine

    templateName

    the name of the template

  • Take a template file and an Encodable type and generate the content to be sent back to the client.

    Declaration

    Swift

    func render<T: Encodable>(filePath: String, with: T, forKey: String?,
                options: RenderingOptions, templateName: String) throws -> String

    Parameters

    filePath

    The path of the template file to use when generating the content.

    with

    A value that conforms to Encodable which is used to generate the content.

    forKey

    A value used to match the Encodable values to the correct variable in a template file. The forKey value should match the desired variable in the template file.

    options

    rendering options, different per each template engine.

    templateName

    the name of the template.

  • setRootPaths(rootPaths:) Default implementation

    Set root paths for the template engine - the paths where the included templates can be searched

    Default Implementation

    Declaration

    Swift

    func setRootPaths(rootPaths: [String])

    Parameters

    rootPaths

    the paths where the included templates can be