Deprecated: Optional parameter $post_id declared before required parameter $field is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php on line 54

Deprecated: Optional parameter $value declared before required parameter $field is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php on line 166

Deprecated: Optional parameter $post_id declared before required parameter $field is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php on line 166

Deprecated: Optional parameter $key declared before required parameter $value is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/ajax/class-acf-ajax.php on line 76

Notice: Function wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the codepen-embed-script handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/jwblogger/jwBlogger/wp-includes/functions.php on line 6114

Deprecated: Optional parameter $i declared before required parameter $post_id is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 720

Deprecated: Optional parameter $i declared before required parameter $post_id is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 786

Deprecated: Optional parameter $name declared before required parameter $field is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1038

Deprecated: Optional parameter $i declared before required parameter $post_id is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1074

Deprecated: Optional parameter $i declared before required parameter $post_id is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1126

Deprecated: Optional parameter $id declared before required parameter $field is implicitly treated as a required parameter in /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-gallery.php on line 296

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/jwblogger/jwBlogger/wp-content/plugins/advanced-custom-fields-pro/includes/acf-value-functions.php:54) in /home/jwblogger/jwBlogger/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":397,"date":"2018-08-12T10:56:52","date_gmt":"2018-08-12T17:56:52","guid":{"rendered":"http:\/\/blog.jeffwilkerson.net\/?p=397"},"modified":"2018-08-12T10:56:52","modified_gmt":"2018-08-12T17:56:52","slug":"wordpress-development-with-twig-and-timber","status":"publish","type":"post","link":"https:\/\/blog.jeffwilkerson.net\/2018\/08\/12\/wordpress-development-with-twig-and-timber\/","title":{"rendered":"WordPress Development with Twig and Timber"},"content":{"rendered":"

I got to admit, I was very very excited when I finally discovered Timber<\/a>, a tool that creates the ability to use Twig <\/a>templates with WordPress. As a front-end developer, using Twig templates allows me to focus more on the HTML I need to create. It frees me from polluting my templates with random PHP functions, and I can create reusable template snippets that I can use in other projects. To put in another way, Twig allows me to abstract PHP and server-side code out of my HTML templates so that I can focus better on the markup I need to develop. I’m not scared of PHP – I just don’t want to think about it when I’m working on client-side markup.<\/p>\n

Without Twig, here is the code you need to write to display an image:<\/p>\n

$thumb_id = get_post_thumbnail_id($post->ID);\n$url = wp_get_attachment_url($thumb_id);\n<img src=\"<?php echo $url; ?>\" alt=\"Thumbnail for <?php echo $post->post_title; ?>\" \/>\n<\/pre>\n

And thats just for a thumbnail image. Imagine using this code to show a gallery of images, or if you had to use a srcset<\/span> attribute to ensure the appropriate image gets loaded, given the user’s screen size.<\/p>\n

With Timber, that code now looks like:<\/p>\n

<img src=\"{{post.thumbnail.src}}\" alt=\"Thumbnail for {{ post.title }}\" \/><\/pre>\n

Much cleaner and concise, yes? Ref: https:\/\/www.upstatement.com\/timber\/#object-oriented-posts-etc<\/a><\/p>\n

Getting Started<\/h2>\n

Getting started with Timber was way easy. I followed the steps in “Setup<\/a>” tutorial with no problem – I love tools that come with clear and unambiguous instructions.<\/p>\n

The first time I installed Timber, I installed the plugin found on WordPress.org<\/a>, Then I downloaded the Timber starter theme<\/a> so I could begin to play with the templates. No other configuration was necessary.<\/p>\n

Useful Links<\/h2>\n