Next level Twig

megan_m

If you’re finally getting around to learning TWIG, it might be difficult to figure out where to start. The documentation is in multiple places, some of it is confusing for non-programmers, and it’s hard to pick out the parts that you actually need to learn.

This session will give you a quick start by reviewing the most common things you will use in Twig. This includes:
 

  • Basic Syntax
  • Twig filters and Drupal-specific filters     
  • Using variables, conditionals, and loops
  • Adding classes 
  • Creating paths, urls, and links
  • Formatting dates
  • Attaching libraries
  • Extending templates with blocks, embeds, and includes
  • Debugging
  • Using contrib modules to extend Twig functionality 


If all of the above is completly new to you, don't worry: it will all be explained!

This session is low on slides and high on code samples. We'll spend most of the time looking at real template files and examining all the ways Twig can help you to structure your code.

It will not cover turning on theme debugging and overriding template files. This information is explained well on Drupal.org and elsewhere.

Wondering about Twig 2 and Drupal 9? We'll talk about that too (hint: not much is changing).

Learning Objectives

  • use a variety of Twig features including filters, paths and urls, variables, if statements, and more
  • explain the difference between blocks, embeds, and includes, and use those structures to reduce code duplication
  • debug twig output and access deeper parts of a render array

Target Audience

Developers who want to get better at writing TWIG. 

Prerequisites

Attendees should have a general understanding of how Drupal themes are structured. Extensive knowledge of templating in Drupal 7 is not required.

Track

Development & Coding

Tags

drupal 8
front-end development
theming

Experience Level

Intermediate

If no timezone is set on your profile, time is displayed in UTC.
Update your profile's timezone