How to get rid of the code mess – Timber & ACF

Back in the WordPress environment.
It is a fourth website within this month I decided to use the Timber/Twig template engine and I must say it makes the work much more enjoyable and the result clean and the code nicely readable.
The Twig syntax and logic makes so much sense to me. It is pleasure to read the code.

All the PHP junk is gone, not all 100% indeed but most of it. Plus the separation of logic/function out of template is really the way I like.
The big plus is that the template logic can be easily redone into Symphony (PHP), Django (Python), or even Ruby on Rails (Ruby). Which not useful in everyday work but a big plus if the time comes.
There are so many pluses to build on top of Twig syntax..

Why next template logic on top of WordPress?

Simply because the native WordPress PHP based template junk is just complete mess.

Ohh. I almost forgot .. The Advanced Custom Fields paired with Timber ..sooo grate! The integrations is really smooth. In a fact, the Timber is made with ACF in mind from the ground.

This is how you get the image source the junk way:
<?php $img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘medium’ );
echo $img; ?>

and here the clever way:
{{ post.thumbnail.src(‘medium’) }}

What if you want different image size on the way? With bare WordPress you have to register image size, which populates your upload folder with unnecessary image sizes made out of all future uploads..

With Timber You just do once and exclusively for that case:
{{ post.thumbnail.src(‘medium’)|resize(960, 300) }}
Make a small project on it. Sure it takes some time to get used to it, but you won’t be sorry.

Once more again, link to Timber.