Top Banner
1
41

Maintainable theming

May 13, 2015

Download

Documents

Wunderkraut

Learn how to do maintainable Drupal theming. This presentation was given at DrupalCamp Stockholm 2013
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Maintainable theming

1

Page 3: Maintainable theming

MaintainableDrupal Theming

3

Page 4: Maintainable theming

Why

Client: the white-space on the news overview page is wrong!

body #page .view-news .views-row div.node .node-section.clear-block { margin-top: 0 !important;}

4

Page 5: Maintainable theming

Agenda

‣ Drupal is special

‣ Optimize your design input

‣ Optimize your Drupal HTML

‣ Write maintainable CSS

‣ Build a maintainable theme

5

Page 6: Maintainable theming

Drupal is special

6

Page 7: Maintainable theming

Drupal is a CMS

‣ Highly customizable

‣ What if content is added?

‣ What if a block is moved?

7

Page 8: Maintainable theming

Content-first approach

‣ First content types, taxonomy, users, comments

‣ Pages assembled from different sources

‣ Theming should support this

8

Page 9: Maintainable theming

Optimize your design input

9

Page 10: Maintainable theming

Problems with designs

‣ A design is static

‣ Not all pages will be designed

‣ Designs are rarely consistent

‣ A design reflects the ideal situation

10

Page 11: Maintainable theming

Solutions

‣ Ask for a Style Guide

‣ Analyze the design

‣ Keep designers involved

11

Page 12: Maintainable theming

Style Guide

‣ All recurring design elements and interactions

‣ Leading in case of inconsistencies.

12

Page 13: Maintainable theming

Style Guide‣ Site elements:

‣ Navigations: including mouse-over and active states

‣ One or more block templates

‣ A pager

‣ Message boxes: warning, confirmation and error

‣ A form. Typically useful for the contact form

‣ A list of the most important colors

13

Page 14: Maintainable theming

Style Guide

‣ Typography:‣ Headings: H1, H2, H3 and H4

‣ Links: color and (optional) underline. Also define a mouse-over state

‣ Paragraph: for default text the line-height and space between text should be defined

‣ (Un)ordered list: How does it look in content?

14

Page 15: Maintainable theming

Analyze the design‣ Print all designs

‣ Look for patterns:

‣ Block styles

‣ Image styles

‣ View Modes

‣ Regions...

‣ Convert patterns to HTML tags/classes/styles

15

Page 16: Maintainable theming

Optimize your HTML

16

Page 17: Maintainable theming

“ The Views output contains a rich set of div tags allowing

fine-grained CSS control over the output. ”

17

Page 18: Maintainable theming

Remove HTML

‣ Clean up template files

‣ Examples: Panels, Views, Field

‣ Use Display Suite (Field Templates)

‣ One-time effort

18

Page 19: Maintainable theming

Before cleanup

19

Page 20: Maintainable theming

After cleanup

20

Page 21: Maintainable theming

Module unaware HTML

‣ .panel-pane .pane-title {} vs.block > h2 {}

‣ page.tpl.php vs Panels Layout

‣ Views specific classes

21

Page 22: Maintainable theming

Add own classes

‣ Block class: http://drupal.org/project/block_class

‣ Views

‣ Display Suite

‣ Panels

22

Page 23: Maintainable theming

Write maintainable CSS

23

Page 24: Maintainable theming

Functional selectors

‣ Theme a functional element, not a Drupal module:

‣ Bad:

‣ .views-articles .views-row {}

‣ .views-row {}

‣ Good:

‣ .article-teaser {}

‣ .item-list li {}

24

Page 25: Maintainable theming

As generic as possible

.field

vs

.page-article #content div.node div.field-title

25

Page 26: Maintainable theming

Avoid overwrites

‣ Remove Drupal and module CSS ‣ function theme_css_alter(&$css) {

unset($css['modules/system/system.menus.css']);}

‣ Dare to rework existing CSS as features are added.

26

Page 27: Maintainable theming

Drupal CSS standards

‣ http://drupal.org/node/1887862

‣ .quote { margin-left: 15px; font-style: italic;}

27

Page 28: Maintainable theming

Build a maintainable theme

28

Page 29: Maintainable theming

Theming is...

‣ Basic design

‣ Features

‣ Reusable styles

29

Page 30: Maintainable theming

Basic design

‣ All generic elements: header, footer, layout

‣ Style Guide: navigation, typography, colors, links etc

‣ Simple content page with mixed typographical content.

30

Page 31: Maintainable theming

Features

‣ Examples: news, blog, slideshow

‣ Separate CSS files

‣ Clear separation between reuse of styles and custom CSS

31

Page 32: Maintainable theming

Styles

‣ Examples: list of teasers, block styles

‣ Power of Sass

‣ Add as you go

32

Page 33: Maintainable theming

Power of Sass

‣ Mixins and extendables

‣ Variables

‣ Selector nesting

33

Page 34: Maintainable theming

Power of Sass

.node-news { .view-mode-teaser { @extend %teaser; color: $grey; @include border-radius(3px); margin-top: 0; }}

34

Page 35: Maintainable theming

Wundertheme

‣ Custom starter theme

‣ Beta

‣ https://github.com/Krimson/wundertheme.git

35

Page 36: Maintainable theming

In Summary

36

Page 37: Maintainable theming

In Summary

Client: the white-space on the news overview page is wrong!

body #page .view-news .views-row div.node .node-section.clear-block { margin-top: 0 !important;}

37

Page 38: Maintainable theming

Power of Sass

.node-news { .view-mode-teaser { @extend %teaser; color: $grey; @include border-radius(3px); margin-top: 0; }}

38

Page 39: Maintainable theming

In Summary

‣ Drupal is special

‣ Optimize your design input

‣ Optimize your Drupal HTML

‣ Write maintainable CSS

‣ Build a maintainable theme

39

Page 40: Maintainable theming

Questions?

40

Page 41: Maintainable theming

41