Front-end engineer with a passion for learning something new every day

Drupal 8 Theming: How I got Inspired by Drupal All Over Again

When Drupal 8 and its innovative architectural changes were first announced several years back, there were a variety of reactions within the community ranging from euphoria and elation, to FUD and potential abandonment of the platform altogether. I remember feeling caught in the middle of these two camps, not really being able to come to any conclusion for some time to come.

Admittedly, I had my reservations about Drupal 8 but I really wanted to give it a chance. I experimented with it while in the early alpha stages, but for a themer it was frustrating as there were constant code changes to core (as was to be expected), and the theming layer was constantly evolving.

In fact, these broad changes with Drupal 8 prompted the forking of Drupal 7 into a new platform called Backdrop CMS, which would carry the essence of Drupal 7 into the future while taking some of the refinements made to Drupal 8 and splitting the difference. I tested out Backdrop during that time as well, but honestly I was not happy with Backdrop's theming layer; it seemed disjointed to me.

Getting inspired all over again

Fast forward to 2016 and now that Drupal 8 has been out for almost six months, I decided to dig in again. It all started with attending SANDCamp here in San Diego at the end of February. Thanks to my company, Jackson River for making my attendance to the camp possible, I was inspired by Drupal all over again and moreover, by Drupal 8. I was especially taken by how awesome and logical theming is in Drupal 8; it's now super refined and powerful. At the camp, I took an all day Drupal 8 theming workshop led by the good folks at Chapter Three, and by the end of the day I saw the light and was a believer.

A lot of this has to do with two new base themes in Drupal 8 called "Classy" and "Stable," as well as the underlying Twig and YAML frameworks. Out of the box, Classy and Stable each give you 100 + templates to override and modify into your own custom sub-theme.

Classy has class

"Its purpose is to provide many classes throughout the markup that help annotate and describe markup elements that
render on the page. In the past, the extra effort that Drupal applies to elements in annotating them this way has been viewed as
helpful by some and a hindrance by others. In Drupal 8, you now have the option of either including or excluding this extra help."

Go minimal, don't use classy

"Not using Classy is a great idea when you don't want the classes defined by Drupal to
conflict with CSS and JavaScript frameworks being used by your theme. Excluding Classy
gives you full responsibility over the classes your theme has."

I'm now in the process of designing and developing a Drupal 8 theme and I'm still deciding whether to use Classy or Stable as my base-theme. I'm thinking I'll use Classy and then in any of my template sub-theme overrides, I can alter or remove markup as needed. Using either of these as a base-theme in combination with Twig debugging makes Drupal 8 a theming force to be reckoned with.

Less preprocessing, more Twig

Much of what used to be done altering things like field markup with theme_field in Drupal 7 is much more accessible and alterable directly in Twig templates now in Drupal 8. Thus, less of a need to use theme preprocess functions compared with Drupal 7. However, when you do need to write a preprocess function, you'll typically use minimal code. The other thing that I love with Drupal 8 theming is that theme hooks seem to be more accessible and easier to write via quick and easy alter hooks. Write a hook and magically see your new template suggestion(s) appear in your Twig debug area. In addition, the Drupal 7 module, View Modes in now part of Drupal 8 core so you get easy creation of view modes AKA Display Modes with a UI right out of the box. This is great news for themers, and I've become a huge fan theming using view modes over the past few years.

Devel Kint

As a themer, if you were used to exploring data arrays in Drupal 7 with Devel's venerable dpm functions, with Drupal 8 you can use Devel "Kint". Kint is somewhat mind boggling at first but it does do very similar things as dpm did with Drupal 7. The one big feature missing for me with Kint is a search function similar to the Search Krumo module in Drupal 7. I hope that becomes available in the future. Kint most definitely comes in handy for designing your theme hooks.

Summary

I am really excited about theming with Drupal 8, I feel like I did when I first discovered and started developing with Drupal 6 back in 2009. In the coming months here on my blog, I hope to share some of this new-found theming knowledge. One of the main takeaways is that Drupal 8 theming presents far less of a barrier to entry than I thought it would.

Resources

Tags

Read other blog posts