You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Example
There are {{ articles.count }} articles.
<ul>
{%forarticleinarticles%}
<li>{{ article.title }} by {{ article.author }}</li>
{%endfor%}
</ul>
import Stencil
structArticle{lettitle:Stringletauthor:String}letcontext=["articles":[Article(title:"Migrating from OCUnit to XCTest", author:"Kyle Fuller"),Article(title:"Memory Management with ARC", author:"Kyle Fuller"),]]letenvironment=Environment(loader:FileSystemLoader(paths:["templates/"]))letrendered=try environment.renderTemplate(name:"article_list.html", context: context)print(rendered)
Philosophy
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: