Skip to content
Render Mustache templates in Vapor
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Resources/Views
Sources
Tests
.gitignore
.swift-version
.travis.yml
LICENSE
Package.swift
README.md

README.md

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])
You can’t perform that action at this time.