the new theme layer in drupal 8 7: negative object or array? •mixed data types (strings, objects...

73
THE NEW THEME LAYER IN DRUPAL 8 Jen Lampton ~ @jenlampton www.jenlampton.com Saturday, March 30, 2013

Upload: truongquynh

Post on 25-May-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

THE NEW THEME LAYERIN DRUPAL 8

Jen Lampton ~ @jenlamptonwww.jenlampton.com

Saturday, March 30, 2013

Page 2: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

WHY?

Saturday, March 30, 2013

Page 3: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

DRUPAL 7

 

Saturday, March 30, 2013

Page 4: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

DRUPAL 7: NEGATIVES

 

Saturday, March 30, 2013

Page 5: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

DRUPAL 7: NEGATIVE

Drupalism noun Something that only exists in Drupal.

•Drupal-specific template conventions

Saturday, March 30, 2013

Page 6: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

DRUPAL 7: NEGATIVE

Object or Array?

•Mixed data types (strings, objects & arrays)

Saturday, March 30, 2013

Page 7: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

DRUPAL 7: NEGATIVE

 

print or print render() ?

•Different methods of printing

Saturday, March 30, 2013

Page 8: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

DRUPAL 7: NEGATIVE

 

(because PHP is insecure)

PHPTemplate is insecure

Saturday, March 30, 2013

Page 9: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

NEGATIVE

Too many template files

Saturday, March 30, 2013

Page 10: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 Waaaaaaaaay too many theme functions

NEGATIVE

Saturday, March 30, 2013

Page 11: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

DRUPAL 7: NEGATIVE

too many complex of subsystems

Saturday, March 30, 2013

Page 12: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

DRUPAL 7: NEGATIVE

Satanic?

Saturday, March 30, 2013

Page 13: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

DRUPAL 7: NEGATIVE

Drupal 7 is too hard to learn!

Saturday, March 30, 2013

Page 14: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

THIS IS A LOT OF STUFF•Drupal-specific template conventions•Mixed data types (strings, objects & arrays)

$node->nid vs $content[‘links’]•Different methods of printing

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure•Two ways to override markup

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions•Complex mix of subsystems•Difficult to learn for newcomers (and D6 veterans)

Saturday, March 30, 2013

Page 15: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

A NEW THEME LAYER?

Principals to guide us.BADCamp, 2012.

Saturday, March 30, 2013

Page 16: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothingCore default markup should strive for semantic simplicity, with few HTML elements, added only as needed

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 17: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases

Don't assume you know what people want or add features based on "What-if?" Think about the 90% of use cases.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 18: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools

Give front-end experts a way to achieve specific goals; goals that apply to the remaining 10% of use cases. Keep in mind that complex problems may require complex solutions.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 19: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools4. Consolidate

"Your markup is not special." Don't make something new. Work toward common theme functions that modules leverage (i.e. a Theme Component Library).

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 20: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools4. Consolidate5. Visibility

You should be able to see what's going on in a template without reading docs. Twig provides a lot of this by virtue of its syntax (it looks like HTML). Form follows function.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 21: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools4. Consolidate5. Visibility6. Consistency

Do the same things everywhere, follow patterns. Use similar variable names across templates if they represent similar things.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 22: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools4. Consolidate5. Visibility6. Consistency7. Don't dumb it down

Complexity should be reduced but not obscured. Themers *can* understand template logic and loops. When complexity does happen, use comments to explain why.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 23: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

Principals to guide us

1. Start with nothing2. Build from use cases3. Provide tools4. Consolidate5. Visibility6. Consistency7. Don't dumb it down8. Organization should be driven by meaning and semantics over technical convenience

Consider what an element means rather than how it structurally appears. Names and locations of templates should be self-evident. Themers want to see markup in templates, not abstraction.

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 24: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

A NEW THEME LAYER?

Saturday, March 30, 2013

Page 25: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

well documented

Saturday, March 30, 2013

Page 26: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

extensible

Saturday, March 30, 2013

Page 27: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

secure

Saturday, March 30, 2013

Page 28: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

well-tested

Saturday, March 30, 2013

Page 29: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

fast

Saturday, March 30, 2013

Page 30: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

IDE integration

Saturday, March 30, 2013

Page 31: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

recognizable syntax

Saturday, March 30, 2013

Page 32: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

by Symfony’s author, Fabien Potencier

Saturday, March 30, 2013

Page 33: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIGwhat does it look like?

Saturday, March 30, 2013

Page 34: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

what does it look like?

TWIG

Saturday, March 30, 2013

Page 35: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

print with {{ }}

TWIG

Saturday, March 30, 2013

Page 36: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

commands with {% %}

TWIG

Saturday, March 30, 2013

Page 37: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

comments with {# #}

TWIG

Saturday, March 30, 2013

Page 38: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

simple and intuitive

TWIG

Saturday, March 30, 2013

Page 39: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

A single way to override markup!

All theme functions become template files!

TWIG

Saturday, March 30, 2013

Page 40: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

less code than PHP tempates

TWIG

Saturday, March 30, 2013

Page 41: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

D7

D8

theme_username becomes username.html.twig

less code than PHP tempates

Saturday, March 30, 2013

Page 42: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

D7

D8

theme_image becomes image.html.twig

less code than PHP tempates

Saturday, March 30, 2013

Page 43: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

D7

D8

theme_link becomes link.html.twig

less code than PHP tempates

Saturday, March 30, 2013

Page 44: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG

D7

D8

theme_item_list beomes item_list.html.twig

less code than PHP tempates

Saturday, March 30, 2013

Page 45: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions•Mixed data types (strings, objects & arrays)

$node->nid vs $content[‘links’]•Different methods of printing

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure•Two ways to override markup

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions•Complex mix of subsystems•Difficult to learn for newcomers (and D6 veterans)

Saturday, March 30, 2013

Page 46: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions

Twig is used elsewhere on the web....is syntactically similar to other languages,

...and looks a lot more like HTML.

Saturday, March 30, 2013

Page 47: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays)

$node->nid vs $content[‘links’]All template variables are accessed consistently:

node.nidcontent.links

Saturday, March 30, 2013

Page 48: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing

print $node->nid vs print render($content[‘links’])We’re removed calls to render() from templates:

{{ node.nid }}{{ content.links }}

Saturday, March 30, 2013

Page 49: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure

All variables will be *automatically* sanitized....and most PHP functions cannot be executed in

template files.

Saturday, March 30, 2013

Page 50: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure FIXED•Two ways to override markup

Templates: *.tpl.php vs functions: theme_foo()All theme functions are converted to

template filesnode.tpl.php becomes node.html.twig

theme_table() becomes table.html.twig

Saturday, March 30, 2013

Page 51: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure FIXED•Two ways to override markup FIXED

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions

We’re working on this right now (Sprints!)

Saturday, March 30, 2013

Page 52: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure FIXED•Two ways to override markup FIXED

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions @todo•Complex mix of subsystems

We can remove all theme functions, and potentially render, process & (maybe) preprocess.

Saturday, March 30, 2013

Page 53: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remember the complexity of Drupal 7?

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 54: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remove theme functions (and overrides) entirely.

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 55: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remove process.

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 56: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remove render.

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 57: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remove page alter?

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 58: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

remove preprocess?

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 59: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

look what would happen in Drupal 8.

REMEMBER DRUPAL 7?

Saturday, March 30, 2013

Page 60: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure FIXED•Two ways to override markup FIXED

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions @todo•Complex mix of subsystems @todo•Difficult to learn for newcomers (and D6 veterans)

Saturday, March 30, 2013

Page 61: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

 

REMEMBER DRUPAL 7?•Drupal-specific template conventions FIXED•Mixed data types (strings, objects & arrays) FIXED

$node->nid vs $content[‘links’]•Different methods of printing FIXED

print $node->nid vs print render($content[‘links’])•PHPTemplate is insecure FIXED•Two ways to override markup FIXED

Templates: *.tpl.php vs functions: theme_foo()•Many template files, many similar theme functions @todo•Complex mix of subsystems @todo•Difficult to learn for newcomers (and D6 veterans)

Consistency FTW

Saturday, March 30, 2013

Page 62: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 63: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Twig template inheritance

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 64: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Twig template inheritance

•Awesome variable inspection: Twig’s dpm()

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 65: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Twig template inheritance

•Awesome variable inspection: Twig’s dpm()

•Templates are safe enough for in-browser editing

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 66: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Twig template inheritance

•Awesome variable inspection: Twig’s dpm()

•Templates are safe enough for in-browser editing

•Possible performance gains: (much TBD) faster than render()?

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 67: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Twig template inheritance

•Awesome variable inspection: Twig’s dpm()

•Templates are safe enough for in-browser editing

•Possible performance gains: (much TBD) faster than render()?

•2-way communication between UI and code: The UI can understand what variables exist (or not) in a template file

TWIG: OTHER WINS

Saturday, March 30, 2013

Page 68: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

QUESTIONS?

Saturday, March 30, 2013

Page 69: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

HOW CAN I HELP?

Saturday, March 30, 2013

Page 70: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Finish converting all existing core *.tpl.php files to Twig templates (sandbox) DONE~ISH•Finish converting all existing core theme functions to Twig templates (sandbox) DONE~ISH•Create & test patches for each module (core) HELP!•Help clean up markup in core (sandbox/core) HELP!•Consolidate similar templates (core) HELP!•Identify & enable template suggestions (core) HELP!•Rethink preprocess / __to_string() methods (maybe D9?)•Convert renderable arrays into Twig objects (maybe D9?)

•More TBD

NEXT TASKS

Saturday, March 30, 2013

Page 71: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

•Create & test patches for each module

live demo?

JUST DO IT!

Saturday, March 30, 2013

Page 72: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

A NEW THEME LAYERFOR DRUPAL 8

Saturday, March 30, 2013

Page 73: THE NEW THEME LAYER IN DRUPAL 8 7: NEGATIVE Object or Array? •Mixed data types (strings, objects & arrays) Saturday, March 30, 2013 DRUPAL 7: NEGATIVE print or print render() ? •Different

photo credits:lolcat-flexible

http://cheezburger.com/2679924736

anything is possible pebbleshttp://www.invergordontours.com/aip.html

lolcat questionmark http://icanhascheezburger.com/2007/10/31/11197/

wheel-reinventedhttp://www.brainwads.net/drewhawkins/2012/01/dont-re-invent-the-wheel-make-something-better/

objectshttp://2teachers1classroom.blogspot.com/2009_02_01_archive.html

shapeshttp://englishclass.jp/reading/topic/For_Screening_Purposes_Only

securehttp://blog.stratepedia.org/2010/06/03/what-is-a-secure-site/

consistencyhttp://icsigns.org/press/2010/03/23/consistency-staying-on-the-mark/

twig bird comichttp://s302.photobucket.com/albums/nn105/walkseva/?action=view&current=thebirdneedsthattwig.gif&currenttag=bird%20park%20twig%20comic%20need%20it

twig docs screenshotshttp://twig.sensiolabs.org/documentation

twig speed graphshttp://phpcomparison.net/

python iconhttp://python-hosting.org/

ruby iconhttp://itmediaconnect.ro/en/web

django logohttp://py-arahat.blogspot.com/2010/08/django-vs-pylons.html

symfony logohttp://symfony.com/logo

scotch glasshttp://www.thespir.it/articles/scotch-101/?viewall=1

Saturday, March 30, 2013