What is Timber/Twig?

What is Timber/Twig?

April 25, 2018 By Jake

In many of the pages and posts on this site, I refer to Timber/Twig. So what is it? In my opinion, it is a tool sent from heaven to write code efficient WordPress templates. Yes, it is a template framework.

What makes Twig different? Twig sets itself apart from other frameworks as it offers additional layers of security and more functionality. You can use both JavaScript and HTML attributes.

More in-depth Twig:

  • It compiles the template code down to optimized PHP code reducing the overhead of the template to a bare minimum (Twig makes your template fast).
  • It has a sandbox where it evaluates untrusted code (Twig is secure).
  • Developers can create their own filters and tags (Twig is flexible).
  • Other CMSs use it as their default templating language (Drupal 8).

Ok, what is the Timber for? Timber is a plugin that enables the use of TWIG in WordPress. It handles and defines for Twig the functions already present in WordPress so you do not have to define them yourself.

The use of this plugin and Twig separate the HTML template from the PHP used in WordPress. When you relieve that overhead from WordPress, the CMS can perform its primary function Metternich — delivering content.

The best feature, other than speed, is that the code is much easier to read and understand, that the usual mix of HTML and PHP.

It is best said in the words of the plugin developer, Upstatement
Timber: a faster, easier and more powerful way to build themes. Because WordPress is awesome, but the loop isn’t.

Take the time to read the linked article. It will ignite your excitement for templating.