All Projects → vapor-community → mustache-provider

vapor-community / mustache-provider

Licence: MIT License
Render Mustache templates in Vapor

Programming Languages

swift
15916 projects
HTML
75241 projects

Vapor Mustache

Vapor RenderDriver implementation for Mustache.

Installation

Package

To add VaporMustache, add the following package to your Package.swift.

Package.swift

.Package(url: "https://github.com/qutheory/vapor-mustache.git", majorVersion: 0, minor: 8)

Provider

This package includes a Vapor Provider which makes it easy to add as a dependency.

import Vapor
import VaporMustache

let app = Application()

//routes, etc

app.providers.append(VaporMustache.Provider())
app.start()

Manual

If you don't want to use the Provider, set the MustacheRenderer() on your View.renderers for whatever file extensions you would like to be rendered as Mustache templates.

main.swift

import VaporMustache

//set the mustache renderer
//for all .mustache files
View.renderers[".mustache"] = VaporZewoMustache.MustacheRenderer()

Includes

Includes let you load other mustache templates into your template with a syntax like {{> header}}.

To use includes, you must specify them ahead of time to the MustacheRenderer.

Provider

Simply add them as the Provider's includeFiles.

let mustache = VaporMustache.Provider(withIncludes: [
	"header": "Includes/header.mustache",
	"footer": "Includes/footer.mustache"
])

let app = Application(providers: [mustache])

The path will be appended to Resources/Views/... by default.

Manual

The MustacheRenderer accepts a dictionary of files where the key is the include name and the value is the file path relative to the working directory.

public init(files: [String: String])
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].