This document discusses strategies for creating lean and maintainable Drupal 8 themes. It explains some of the complexity that can arise from Drupal's flexible theming system and powerful configuration options. It then provides recommendations for limiting complexity, such as being consistent, recognizing unnecessary complexity, considering maintainability, adding documentation, and refactoring existing complex themes. Specific techniques recommended include using libraries and view modes appropriately, limiting the use of templates and preprocess functions, and writing clean and reusable CSS/Sass code.
8. • Why are Drupal themes complex?
• Looking at our Drupal 8 theming toolset
• Managing and limiting the complexity
Creating a Lean, Mean
Drupal 8 Theme
10. Design Flexible Theme System
Powerful Configuration
Log in
name
password
Login
Log in
name
password
Login
Joe joined...
Lisa joined...
Peter joined...
Mary joined...
Who's new?
Ever wondered?
Great news
Fantastic offer for you
CSS
Functions
ViewsPanels
Display Suite
Templates
Layout
Typography
Regions
Branding
33. Design Flexible Theme System
Powerful Configuration
Log in
name
password
Login
Log in
name
password
Login
Joe joined...
Lisa joined...
Peter joined...
Mary joined...
Who's new?
Ever wondered?
Great news
Fantastic offer for you
CSS
Functions
ViewsPanels
Display Suite
Templates
Layout
Typography
Regions
Branding
47. Contextual CSS
• Use libraries when there is a significant
body specific CSS + JS
Search CSS + JS
Global CSS
Store CSS + JS
48. Too Many Libraries?
Only create separate libraries for sections of
the site that are separate + specific
Search Store
Front Page User ProfilesLanding Pages
53. Name and use your
variables consistently
Writing Good SASS
54. Writing Good SASS
• @extend should always appear before
properties
• @include should appear second
• Review the CSS that gets generated
https://github.com/anthonyshort/idiomatic-sass
62. Preprocess Functions:
The Good!
• Transform content before it gets rendered in
templates
• Link one field to another
• Change the format of the submitted text
• Add new variables to the render array
63. Preprocess Functions:
The Ugly!
• Formatting field types
• Overrides that depend on a node ID
• Database calls to style past events and ‘on
tour’ events differently
• Commerce line item calculations for
currencies
• Hiding results of a view
64. Preprocess vs. Template
• Preprocess
• Adding logic
• Adding new
variables
• When the output
depends on the
context
!
!
• Templates
• Adding classes
• Wrapping fields
in different
markup
• Bundling fields
together
76. 1. Be consistent
• Make choices and stick with them
• If you’re using view modes, define and use
them consistently
• If you’re using the Bootstrap theme, apply
the Bootstrap classes for all layouts
77. 2. Recognize Complexity
• Adding template suggestions to create more
templates
• Adding a lot of classes and IDs
• Adding view modes for each content type
• Adding a lot of theme settings
• Using Node IDs in your preprocess functions
• You have a library for every page
• You have a node template for each content
type
78. 3. Ask: How hard will this be
to maintain?
• How much work will it be to apply this to
a new content type?
• What will happen if the client wants to
add a field?
• What if the branding changes?
• Will your colleague, client, or future self
understand this?
79. 4. Documentation
• What to document:
• Regions that don’t get displayed
everywhere
• Preprocess functions that are complex
• Templates - to indicate what you
changed
• Comment your libraries to say why you
added them
80. 5. Refactor
• If you come across a theme that’s very
complex, refactor it before it’s too late!
• Tools to use:
• Site diff: github.com/evolvingweb/
sitediff
• Visual diff tool like backtrac.io
81. • Introduction to Drupal 8 (1 day)
• Drupal 8 Site Building (2 days)
• Drupal 8 Module Development (2 days)
• Drupal 8 Theming (2 days)
• Zero to Hero Drupal 8 Training (5 days)
training@evolvingweb.ca
evolvingweb.ca/training
Drupal 8 Training