Swiftpack.co - hummingbird-project/hummingbird-mustache as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hummingbird-project.
hummingbird-project/hummingbird-mustache 2.0.0-alpha.1
Mustache template engine for Hummingbird server framework
⭐️ 4
🕓 4 weeks ago
.package(url: "https://github.com/hummingbird-project/hummingbird-mustache.git", from: "2.0.0-alpha.1")


Package for rendering Mustache templates. Mustache is a "logic-less" templating language commonly used in web and mobile platforms. You can find out more about Mustache here.

While Hummingbird Mustache has been designed to be used with the Hummingbird server framework it has no dependencies and can be used as a standalone library.


Load your templates from the filesystem

let library = HBMustacheLibrary("folder/my/templates/are/in")

This will look for all the files with the extension ".mustache" in the specified folder and subfolders and attempt to load them. Each file is registed with the name of the file (with subfolder, if inside a subfolder) minus the "mustache" extension.

Render an object with a template

let output = library.render(object, withTemplate: "myTemplate")

HummingbirdMustache treats an object as a set of key/value pairs when rendering and will render both dictionaries and objects via Mirror reflection. Find out more on how Mustache renders objects here.

Using with Hummingbird

HummingbirdMustache doesn't have any integration with Hummingbird as I wanted to keep the library dependency free. But if you are going to use the library with Hummingbird it is recommended you extend HBApplication to store an instance of your library.

extension HBApplication {
    var mustache: HBMustacheLibrary {
        get { self.extensions.get(\.mustache) }
        set { self.extensions.set(\.mustache, value: newValue) }

extension HBRequest {
    var mustache: HBMustacheLibrary { self.application.mustache }
// load mustache templates from templates folder
application.mustache = try .init(directory: "templates")

You can now access your mustache templates via HBRequest eg HBRequest.mustache.render(obj, withTemplate: "myTemplate")


Hummingbird Mustache supports all standard Mustache tags and is fully compliant with the Mustache spec with the exception of the Lambda support.

Additional features

Hummingbird Mustache includes some features that are specific to its implementation. Please follow the links below to find out more.


Stars: 4
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v2.0.0 Alpha 1
4 weeks ago

Breaking changes

Requires swift 5.7

  • HBMustacheTemplate is a struct
  • HBMustacheLibrary is a struct
  • HBMustacheLibrary.loadTemplates is async
  • Templates no longer store the library they belong to, so to render templates that use partials you need to supply the library at render either via HBMustacheLibrary.render or `HBMustacheTemplate.render(_:library:).

Minor release changes

  • HBMustacheTemplate and HBMustacheLibraryconform to Sendable.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics