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.
Slide deck: http://bit.ly/twig-recipes
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 you know where to look at 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.
With this knowledge under our belt, we will proceed to analyze the recipes where you will learn:
- 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?
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.