Add WordPress Theming COnvenience via Twig and Timber

Today, WordPress is powering a wide array of websites belonging to small as well as large enterprises. Ever since the outburst of WordPress CMS, there's been an incredible increase in the count of businesses which have actually upgraded from other CMSs to the full-featured WordPress CMS. The ease of use and high level of customization available with this web development platform has made room for creation of trendy yet functionally-rich websites. Working in a WordPress environment expects you to get acquainted with a wide variety of plugins/extensions. Developing WordPress themes is perhaps one of the most daunting jobs performed by web professionals.

If you're a WordPress theme customization and development expert, then twig and timber can serve as your best-used tools. Keep on reading this blog as I unveil some amazing information about using twig and timber for developing high-performance WordPress themes.

A brief on Twig

Written by Fabien Portencier, Twig is a contemporary template engine for PHP. This well-tested template language has gone a long way in evolving from the traditional PHP Symphony Framework. As a concise template language, Twig comes with features such as blocks, inheritance etc. Moreover, it also provides better security as compared to the usual PHP templates. Every web developer who's already familiar with Laravel or Rails framework will feel comfortable working with Twig.

Twig serves itself as a meta-language that is specifically used for turning data into formatted output. This output is usually in HTML format but can even be available in XML, JSON or any other plan-text format. As a theme developer, you just need to provide Twig engine with the requisite data and tell which template you want it to deliver, rest everything will be taken care of by the engine itself.

Separation of Data and Design- A major advantage of Twig

As an underlying application, Twig is majorly concerned with collating data, without the need for any individual themes. While using Twig, all your installed plugins would become data focused and the front-end controls such as sliders will become Twig's domain.

How does Twig look like?

Designed to work with any PHP application, Twig can be easily bootstrapped for testing. A plain PHP file that renders a template looks like this:

And the actual Twig template:

The above approach is much more sophisticated as compared to the traditional mix of PHP and HTML.



WP-Twig Integrations-Use it as per requirements

One of the best assets of WP- Twig integrations is that you can choose to use it as per your varying requirements. For example, if you need to do some tweaks to a particular area of your site, you can opt for integrating the portal with Twig configurations.

A Brief on Timber

Timber is one of the building blocks of a starter WordPress theme. It serves as a plugin that can be installed into a WordPress powered site/blog for fetching modern themes/templates which can later be worked on for an overhauled look and feel. Basic functions of Timber include:

  • Separating the logic from the presentation code

  • Writing code maintainable routes

  • Accessing the WP data via clear object oriented methods

By offering full control of the markup, Timber allows you to build the site via easy to understand Twig templates.

What does Timber actually do?

WordPress theming involved the use of mildly unpleasant template syntax and some hideous practices. It can get really frustrating to override functions for setting image size, loop etc. This is when Timber steps in. This plugin simply exposes the WP data in an object oriented way to the Twig templates. In addition to this, Timber also provides WP specific filters that will let you do away with WordPress theming jitters in an intuitive way.

Templating Language- A great addition to the WordPress Core

Currently, templating language is being considered as a potential update to the WordPress core. Although massive theme installs may pose as a major hurdle in the process of building a dataset and making it available to Twig, it doesn't mean you simply need to dismiss the use of this templating language.

Conclusion

Templating languages like Twig bring in big advantages to the theme development process. A well-planned collaboration of Twig with Timber plugin serves as an effective way of super-charging theme development.