default theme implementations: a guide for module developers that want sweet love from morten and...

17
Default theme implementations: a guide for module developers who want sweet love from Morten and JohnAlbin

Upload: john-albin-wilkins

Post on 09-May-2015

4.826 views

Category:

Technology


1 download

DESCRIPTION

Drupalcon San Francisco presentation. Best practices for Drupal module developers as they implement the theme layer.

TRANSCRIPT

Page 1: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Default theme implementations:a guide for module developers

who want sweet love from Morten and JohnAlbin

Page 2: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Who is this guyand what the hell is he going

to talk about?Me and 19 other people wrote 50% of Drupal 7

JohnAlbin (Wilkins)

• Brief overview of the theme layer

• Theme hook suggestions

• Best practices for BYO Implementations

Page 3: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Separation of Concerns

Page 4: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Flow of Themed Content

Page 5: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

A simplified wiring guide to the Theme Layer

Page 6: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Theme Hooks

node

commentpage

links

table

username

pager

item_list

theme(‘theme_hook_name’, $data)

Page 7: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

BE LAZY!Pick an existing theme hook (if you can)

linksimageimage_styleitem_listusername

file_linkhtml_tagmore_linkpagerprogress_bartable

http://api.drupal.org/api/group/themeable/7

Page 8: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

• Less work. (duh.)

• No hook_theme(),no template or theme function,no template_preprocess_HOOK(), etc.

• Just: theme(‘hook’, $vars);

• Themers already know how to style hooks that you re-used.

• Instant integration with other modules!

Laziness advntgs:

Page 9: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Theme hook suggestions

• theme(‘hook’, $vars);

• theme(‘hook__suggestion’, $vars); (D7 only)

• theme($suggestions_array, $vars);

(You, too, can be as awesome as Earl Miles.)

Page 10: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Roll Your Own

• hook_theme() describes theme hooks

• wtf_ftw()

• define default variables

• Picking a theme function or a template

• functions are faster

• templates are easier

Page 11: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Separation of layers (again)

• Data should be passed in as parameters

• Display options should be params or pulled in via a preprocess function

• Meta data should be modifiable by preprocess functions

Page 12: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Things that will make me angry

• Never, EVER pull datafrom inside a theme function

• If you have to call a function to get a value, do NOT put it in a theme function!!!

• Don’t be like D6’s theme_local_menus()

Page 13: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Avoid accidental 3-ways

It’s likely you won’t get what you expect.

Page 14: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Provide context

• Meta data is just important to a themeras the actual data.

Page 15: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Mark-up and CSS

• Do your best.

• Less is more.

• Contextual CSS classes.

• Seek help.

• Mark-up Marines: #drupal-design

Page 16: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Share the love!

Page 17: Default theme implementations: a guide for module developers that want sweet love from Morten and JohnAlbin

Whatdidyouthink?

Step 1) Locate this session on the DCSF site

h.p://sf2010.drupal.org/conference/schedule

Step 2) Click the “Take Survey” link