Ogre Codes

Follow @ogre_codes to get notified when new articles are posted to this site.


Oh Mai, It’s a Stencil! 👨🏻‍💻

Jul 11, 2017 at 5:44 PM

I’ve been using a very good templating engine called “GRMustache” for templates on the blog engine, but I’ve just discovered a new (to me) Swift based template engine called “Stencil” which is modeled after the Django templating engine. I’m sure some people love Mustache templates, but personally I find Django’s template engine to be more expressive and intuitive. Even basic ideas like if logic or for loops are far more expressive in Django. Consider the following short example:



Django Templates/ Stencil

{% for person in people %}
  {% if person.isEmployee %}
    <li>{{ person.name }}</li>
  {% endif %}
{% endfor %}

Anyone can understand the Django template example with a quick scan. The Mustache example is nearly inscrutable even when you understand the basics of how Mustache renders templates. It isn’t even clear if “isEmployee” is a member of people or a global variable.

I’m going to experiment around a bit first, but it’s very likely I’m going to adopt Stencil as the templating engine in favor of the older Mustache based templates.