This week brings another 4 videos in the Drupal 8 Developer Prep collection where we discuss how to use variables in Twig and debug Twig templates.
I will also be heading to BADCamp in a week to do 2 days of Mentored Training with a small band of awesome Drupalists from around the country. If you're going to be there for the training or the rest of the conference, I'll be looking forward to crossing paths.
Enjoy and have an awesome week!
- Chris Shattuck
In this video we create our first Twig template file, get it set up in the right place, and then talk a bit about how variables work in a template.
After creating our template file, the next logical step is to register it with hook_theme() so Drupal knows where it is.
Now that we have our Twig template in the theme registry, it’s time to actually use it. In this video we show one approach to using the template file, which is pushing it through a render array.
One thing that you might be missing if you’re upgrading from Drupal 7 is the flexibility of being able to use PHP in your template to figure out what variables you have to work with. Luckily, Twig comes with a nice feature that allows you do exactly that without the security risk of using PHP directly.