Lies, Damned Lies,
and No Need for Templating Engine

Andrey “Rarst” Savchenko, WordCamp Norway 2014

<?= $lies ?>, <?= $damned['lies'] ?>,
and no need for
{{ templating.engine }}

Andrey “Rarst” Savchenko

Map

Why would I need another
templating engine
when PHP is already one?

Why would I need another
programming language
when PHP is already one?

WordPress theme dev is more than PHP

  1. template hierarchy
  2. template tags API

nana nana nana nana
nana nana nana nana
[gallery] !

Innovation in WordPress templating is dead

WordPress look, you know?

Nothing in last 3 years & 8 major releases

Featuritis cheat sheet

Abstractions

Protect you from code.

Constraints

Protect you from yourself.

PHP Templating Languages Cloud

Mustache — entry to templates & facial hair

  1. context
  2. “logic-less” template
mustache.github.io Mustache logo

Mustache — example

{{#posts}}
	<li>{{post_title}}</li>
{{/posts}}

{{^posts}}
	<li>No posts</li>
{{/posts}}
Mustache logo

Twig — pack leader of PHP templating

  1. context
  2. loader (lexer, parser, compiler)
  3. template (filters, functions, macros, and more)
twig.sensiolabs.org Twig logo

Twig — example

{% for post in posts %}
	<li>{{post.post_title}}</li>
{% else %}
	<li>No posts</li>
{% endfor %}
Twig logo

Timber — WordPress + Twig

  1. context in PHP template
  2. Twig template
  3. OOP context access API
timber.upstatement.com Timber logo

Timber — example

{% for post in posts %}
	<li>{{post.title}}</li>
{% else %}
	<li>No posts</li>
{% endfor %}
Timber logo

Meadow — WordPress templating DSL

  1. template hierarchy
  2. template tags API
  3. DSL API
bitbucket.org/rarst/meadow

Meadow — example

{% loop %}
	<li>{{ the_title() }}</li>
<!--
@TODO {% else %} <li>No posts</li>
-->
{% endloop %}

Are my
templating needs
being met with
adequate tools?

Burst the bubble! Questions?

Rarst.net/slides/templating