Skip to content
Stencil is a simple and powerful template language for Swift.
Swift HTML
Branch: master
Clone or download
mikezucc and ilyapuchka Public Context initialization (#280)
Co-authored-by: Ilya Puchka <>
Latest commit 9c3468e Jan 12, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources Public Context initialization (#280) Jan 12, 2020
docs Fix articles example in the documentation Dec 6, 2019
.gitignore Update to Spectre 0.9.0 (#247) Sep 23, 2018
.swiftlint.yml Rules Nov 11, 2018
.travis.yml Fix swift SIL exception Apr 5, 2019 Update Nov 16, 2019
LICENSE Update some old refs Sep 25, 2018
Package.resolved Fix swift SIL exception Apr 5, 2019
Package.swift Feat: Add support for Swift 4.0 Oct 1, 2018
Package@swift-4.2.swift Compile with Swift 4.2 if possible Sep 25, 2018
Package@swift-5.swift Fix swift SIL exception Apr 5, 2019 Update (#270) Feb 17, 2019
Stencil.podspec.json Update podspec swift version Jan 29, 2019


Build Status

Stencil is a simple and powerful template language for Swift. It provides a syntax similar to Django and Mustache. If you're familiar with these, you will feel right at home with Stencil.


There are {{ articles.count }} articles.

  {% for article in articles %}
    <li>{{ article.title }} by {{ }}</li>
  {% endfor %}
import Stencil

struct Article {
  let title: String
  let author: String

let context = [
  "articles": [
    Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
    Article(title: "Memory Management with ARC", author: "Kyle Fuller"),

let environment = Environment(loader: FileSystemLoader(paths: ["templates/"]))
let rendered = try environment.renderTemplate(name: "article_list.html", context: context)



Stencil follows the same philosophy of Django:

If you have a background in programming, or if you’re used to languages which mix programming code directly into HTML, you’ll want to bear in mind that the Django template system is not simply Python embedded into HTML. This is by design: the template system is meant to express presentation, not program logic.

The User Guide

Resources for Stencil template authors to write Stencil templates:

Resources to help you integrate Stencil into a Swift project:

Projects that use Stencil

Sourcery, SwiftGen, Kitura, Weaver, Genesis


Stencil is licensed under the BSD license. See LICENSE for more info.

You can’t perform that action at this time.