Master Drupal Templates with Twig

Amber Himes Matz

Are you a theme developer, module developer, or front-end developer crafting markup for Drupal 8? You're going to need to master Twig.

Twig is the templating engine used by Drupal, Symfony, Sculpin, and dozens of other PHP projects to separate "business logic" from the presentation and markup of the resulting data. It features a syntax and set of features meant to empower template designers. Once you’ve mastered Twig you can make Drupal output any markup you can imagine.

In this session, you will learn what role Twig plays in Drupal sites, and how to use Twig’s small but powerful feature set.

By the end of this session, you will be able to:

  • Print any variable in a Twig template
  • Add logic with if/else statements
  • Add a comment block to a template file
  • Use a 'for' loop and access items within a loop
  • Find out which variables are available to you in a template
  • Use Twig functions and filters
  • Use Drupal-specific Twig functions and filters
  • Re-use other template code from your theme or another installed theme
  • Learn about Twig features not used in Drupal core that you can use in your theme
  • Know where to find documentation, examples, and resources to learn more
This session is for:
  • Theme developers
  • Module developers
  • Anyone who needs to work with HTML markup in Drupal
  • Anyone who wants to know how Twig works in Drupal specifically
This session is not really for:
  • Drupal 8 experts who already pretty much know everything about how to use Twig 
By the end of this session, you will be able to understand how you can master Twig’s powerful feature set in your Drupal theme.

Session Track

Front End

Experience Level

Beginner

Drupal Version