Contact
Site: US UK AU |
Nexcess Blog

Timber Brings Simplicity To WordPress Theme Development With TWIG Templates

May 19, 2016 0 Comments RSS Feed

WordPress Theme DevelopmentIn an ideal world, web design presentation would be separated from the logic of web applications. To some degree, that’s the case in WordPress, but for theme developers, much of the functionality and the presentation is mixed. Theme files are a combination of HTML and PHP, which can make developing and editing WordPress themes complex and error-prone.

WordPress themes set a high barrier to entry for WordPress users and novice developers who want to create a theme of their own, or simply edit an existing theme. More often than not, theme customization is limited to Googling and pasting in bits of PHP code found on the Internet — not the safest approach.

And, the WordPress Loop is difficult to understand for novices, and even professional WordPress developers often have trouble remembering which functions they should use and where.

All of which is to say that WordPress theme development could use some simplification.

Timber is a project that aims to bring the simplicity of the TWIG template engine to WordPress theme design. TWIG is a PHP template system that is focused on creating output rather than on application logic, although it has a number of simple logical constructs.

The obvious question: isn’t PHP a template language? Why do we need another one? In reality, PHP was once a template language, but it’s now a full-blown programming language with a massive overhead of complexity that simply isn’t necessary if all one wants to do is build a custom WordPress theme or make a few tweaks.

Whereas PHP is bloated, complex, difficult to learn, and verbose, TWIG is concise, simple to hold in your head, and really quite easy to learn for anyone who has a basic grasp of programming concepts and HTML.

One of the reasons that static site generators have become so popular over the last few years is because the template systems they use can be quite easily grasped by designers, developers, and hobbyists who have no desire to tangle with the intricacies of PHP.

Let’s take a look at a simple example from the Timber documentation that shows the difference between PHP and TWIG.

Timber

As you can see, the TWIG version is easy to understand even if you only have a basic knowledge of HTML. The major difference is that variables are enclosed in double curly braces — variables allow you to access data from WordPress. With a combination of HTML, variables, filters, and simple flow control structures for loops and conditionals, it’s possible to build theme templates without the headaches associated with PHP.

If you want to create a custom WordPress theme and don’t have PHP expertise, or build themes that are easy for non-developers to edit, Timber is well worth a look.

Posted in: WordPress