21
One-Hour Drupal 8 Theming By: Chris Doherty October 4, 2014

One-hour Drupal 8 Theming

Embed Size (px)

DESCRIPTION

Mediacurrent's Chris Doherty presented at Drupalcamp Atlanta 2014. With Drupal 8 fast approaching, Chris walked attendees through theming in one hour.

Citation preview

Page 1: One-hour Drupal 8 Theming

One-Hour Drupal 8 Theming

By: Chris Doherty October 4, 2014

Page 2: One-hour Drupal 8 Theming

@Mediacurrent

Agenda

● D8 core structure

● D8 theme structure

● Twig intro

● Live demo

Page 3: One-hour Drupal 8 Theming

I am a designer. I accidentally became a themer.

@Mediacurrent

Page 4: One-hour Drupal 8 Theming

One hour?

Page 5: One-hour Drupal 8 Theming

The D8 core structure

● root/themes

● root/modules

● root/core/themes

● root/core/modules

@Mediacurrent

Page 6: One-hour Drupal 8 Theming

No moredrilling down to contributed themes and modules!

docroot...

sites...

all...

themes...

Page 7: One-hour Drupal 8 Theming

The D8 theme structure

● themename.info.yml

● themename.libraries.yml

● themename.theme

● css folder

● templates folder

● sass folder

● img folder

● js folder

@Mediacurrent

Page 8: One-hour Drupal 8 Theming

theme.info.ymlname: [themename]type: themedescription: This is my custom Drupal 8 Themecore: 8.xengine: twigscreenshot: screenshot.pngstylesheets: all: - css/styles.cssregions: header: ‘Header’...

libraries: - [themename]/[namespace]

@Mediacurrent

Page 9: One-hour Drupal 8 Theming

theme.libraries.yml

[namespace]: version: 1.x js: js/foo.js

@Mediacurrent

Page 10: One-hour Drupal 8 Theming

themename.theme file

● Replaces the template.php file.

● Theme functions go here.

@Mediacurrent

Page 11: One-hour Drupal 8 Theming

What is Twig?

Twig is a template framework that has replaced PHPTemplate in Drupal 8.

It bills itself as fast, secure and flexible.

And it’s very well documented. http://twig.sensiolabs.org/documentation

@Mediacurrent

Page 12: One-hour Drupal 8 Theming

Intro to Twig

There are three delimeters you need to know.

● Print variables: {{ … }}

● Comments: {# … #}

● Execute statements: {% … %}

@Mediacurrent

Page 13: One-hour Drupal 8 Theming

Intro to Twig

● Variables can be accessed directly in Twig.

● Classes can be drilled into to show

attributes: <div {{ attributes }}>

{{ content }}

</div>

● Conditional statements: {% if … %}{% endif %}

● Loops: {% for … %}{% endfor %}@Mediacurrent

Page 14: One-hour Drupal 8 Theming

Intro to Twig

● Blocks: {% block blockname %}...{% endblock %}

● Extends:{% extends ‘.....’ %}

@Mediacurrent

Page 15: One-hour Drupal 8 Theming

Intro to Twig.

PHPTemplate Twig

Page 16: One-hour Drupal 8 Theming

Warm… Warmer… Disco.

Page 17: One-hour Drupal 8 Theming

Where are the twig files?In the system templates folder (/core/modules/system/templates) you’ll find more than 40 templates that are available to override—things like fields, nodes, pages, links.

@Mediacurrent

Page 18: One-hour Drupal 8 Theming

Is that what I think it is?

@Mediacurrent

Page 19: One-hour Drupal 8 Theming

Yes.Most of the Twig template files are in one place, just waiting to be overridden.

@Mediacurrent

Page 20: One-hour Drupal 8 Theming

So let’s create a theme...

Page 21: One-hour Drupal 8 Theming

Roll credits.Questions?