TemplateEngine
public protocol TemplateEngine
Template Engine protocol for Kitura. Implemented by Templating Engines in order to integrate with Kitura’s content generation APIs.
Note
Influenced by http://expressjs.com/en/guide/using-template-engines.html-
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 -> StringParameters
filePathThe path of the template file to use when generating the content.
contextA set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.
-
render(filePath:Default implementationcontext: options: ) 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 -> StringParameters
filePathThe path of the template file to use when generating the content.
contextA set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.
optionsrendering options, different per each template engine
-
render(filePath:Default implementationcontext: options: templateName: ) 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 -> StringParameters
filePathThe path of the template file to use when generating the content.
contextA set of variables in the form of a Dictionary of Key/Value pairs, that can be used when generating the content.
optionsrendering options, different per each template engine
templateNamethe 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 -> StringParameters
filePathThe path of the template file to use when generating the content.
withA value that conforms to Encodable which is used to generate the content.
forKeyA value used to match the Encodable values to the correct variable in a template file. The
forKeyvalue should match the desired variable in the template file.optionsrendering options, different per each template engine.
templateNamethe 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
rootPathsthe paths where the included templates can be
View on GitHub
TemplateEngine Protocol Reference