Lies, Damned Lies, and No Need for Templating Engine

A presentation at WordCamp Norway 2014 in January 2014 in Oslo, Norway by Andrey Savchenko

Slide 1

Slide 1

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

Slide 2

Slide 2

2 Andrey “Rarst” Savchenko • Rarst.net ♦ WPSE ( s.tk/wp ) • QueryPosts.com • Composer.Rarst.net

Slide 3

Slide 3

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

Slide 4

Slide 4

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

Slide 5

Slide 5

5 WordPress theme dev is more than PHP 1. template hierarchy 2. template tags API

Slide 6

Slide 6

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

Slide 7

Slide 7

7 “ Innovation in WordPress templating is dead WordPress look, you know? • get_template_part() — in WP 3.0 (2010) • theme wrappers — around WP 3.2 (2011) Nothing in last 3 years & 8 major releases

Slide 8

Slide 8

8 Featuritis cheat sheet • sandboxing • default escape • template inheritance

Slide 9

Slide 9

9 Abstractions Protect you from code. Constraints Protect you from yourself.

Slide 10

Slide 10

Slide 11

Slide 11

11 Mustache — entry to templates & facial hair 1. context 2. “logic-less” template mustache.github.io

Slide 12

Slide 12

12 Mustache — example {{#posts}} <li>{{post_title}}</li> {{/posts}} {{^posts}} <li>No posts</li> {{/posts}}

Slide 13

Slide 13

13 Twig — pack leader of PHP templating 1. context 2. loader (lexer, parser, compiler) 3. template (filters, functions, macros, and more) twig.sensiolabs.org

Slide 14

Slide 14

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

Slide 15

Slide 15

15 Timber — WordPress + Twig 1. context in PHP template 2. Twig template 3. OOP context access API timber.upstatement.com

Slide 16

Slide 16

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

Slide 17

Slide 17

17 Meadow — WordPress templating DSL 1. template hierarchy 2. template tags API 3. DSL API bitbucket.org/rarst/meadow

Slide 18

Slide 18

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

Slide 19

Slide 19

Are my templating needs being met with adequate tools?

Slide 20

Slide 20

20 Burst the bubble! Questions? • @Rarst • The Loop ( s.tk/chat ) Rarst.net/slides/templating