Keeping Code Out of Your Content and Theme

Speakers: 

You've got a brand new awesome Drupal 7 theme developed for your site. It's wicked fast and stylish, and you're thrilled with how it came out. There's just this one spot where you need to add a template so you can override a value with some PHP. "It's just a little tweak; it won't hurt anyone," you think. "No one ever has to know."

Fast forward two months and your D7 theme is a hodgepodge of module-specific function calls and duplicated formatting blocks. You've got code dotted throughout your content. You even have a template that makes a database call (which you hope you've done enough to secure). What happened? Can you salvage your tainted theme?

And what about Drupal 8? You've heard about the move to the Twig template engine. Forget about your D7 theme hacking, what in the world are you going to do when you don't even have the option to drop code into your D8 templates!?

In this class you'll learn:

  • Why mixing code with templates or content is bad
  • How to plan better to keep code out of where it doesn't belong
  • About using preprocessing methods and other patterns to keep your theme templates squeaky clean
  • How to tackle Views, Blocks, and Pages without succumbing to the PHP Filter
  • Applying these best practices to Drupal 8
  • New cool options Twig offers to facilitate keeping code where it belongs

We'll use examples throughout to learn how to deal with the nightmare, some of them from real world sites.

Schedule info
Experience level: 
Intermediate
Drupal Version: 
Drupal 7.x