Twig Recipes - Making Drupal 8 Render the Markup You Want
“Understanding the process of finding a solution is far more valuable than the solution itself.” - Lea Verou, author of CSS Secrets.
The addition of Twig has revolutionized the way we do theming in Drupal 8. Although very powerful and expressive, it is significantly different to what we did before. Using Twig requires us to take a new approach in order to make Drupal produce the markup that we want. This session is aimed at site builders and themers who want to understand how Twig works in Drupal 8. Basic theming concepts will be presented so no prior knowledge is required to attend.
You will learn what a theme is responsible for when generating a Drupal page. Templates, template nesting, and theme debug will also be explained so that you know where to look when trying to modify the default markup. Twig’s syntax, filters, functions, and tests will be presented as the basis for writing templates. All of these in the context of practical examples some of which come from Drupal core itself.
By the end of the session, you will have a better understanding on how Twig works in Drupal 8 and the thought process required to produce custom markup.
How to pass information from Drupal to Twig?
How to conditionally hide/show fields based on the content of other fields?
How to use image fields as background images?
How to render node content as HTML attributes?