The Drupal 8 The Drupal 8 Theming Experience Theming Experience - - PowerPoint PPT Presentation

the drupal 8 the drupal 8 theming experience theming
SMART_READER_LITE
LIVE PREVIEW

The Drupal 8 The Drupal 8 Theming Experience Theming Experience - - PowerPoint PPT Presentation

The Drupal 8 The Drupal 8 Theming Experience Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional Drupal 8 core committer Team Lead @ Digital


slide-1
SLIDE 1

The Drupal 8 The Drupal 8 Theming Experience Theming Experience

Scott Reeves (Cottser) bit.ly/d8txdca16

slide-2
SLIDE 2

Scott Reeves Scott Reeves

Drupal 8 theme system and Stable (co-)maintainer Provisional Drupal 8 core committer Team Lead @ Digital Echidna Former child pilot

slide-3
SLIDE 3

TX (Themer Experience) TX (Themer Experience) DX (Developer Experience) DX (Developer Experience)

slide-4
SLIDE 4

What we'll cover What we'll cover

Core base themes The without filter Twig theme registry loader Working with libraries

slide-5
SLIDE 5

Two main camps Two main camps

Sensible ⅔ Clean ⅓ Use Classy Use Stable

base theme: classy

my_theme.info.yml: my_theme.info.yml:

slide-6
SLIDE 6

Power to the Power to the templates templates*

{% set classes = [ 'node', 'node--type-' ~ node.bundle|clean_class, node.isPromoted() ? 'node--promoted', node.isSticky() ? 'node--sticky', not node.isPublished() ? 'node--unpublished', view_mode ? 'node--view-mode-' ~ view_mode|clean_class, ] %} {{ attach_library('classy/node') }} <article{{ attributes.addClass(classes) }}>

slide-7
SLIDE 7

Additive vs. Additive vs. Subtractive Subtractive

slide-8
SLIDE 8

{{ content|without('comments', 'links') }} {{ content.links }} {{ content|without('comments') }} {% hide(content.comments) %} {% hide(content.links) %} {{ content }} {{ content.links }} {% show(content.links) %} {# Content with links but without comments #} {{ content }}

Print what you want, Print what you want, when you want when you want

slide-9
SLIDE 9

Referencing other Referencing other Twig templates Twig templates

  • 1. By namespace:
  • 2. Full path from Drupal root:

"core/themes/stable/templates/block/block.html.twig" "@stable/block/block.html.twig"

slide-10
SLIDE 10

Twig blocks Twig blocks

{% extends "@stable/block/block.html.twig" %} {% block content %} <div class="block-content-wrapper"> {{ parent() }} </div> {% endblock %} <div{{ attributes }}> {{ title_prefix }} {% if label %} <h2{{ title_attributes }}>{{ label }}</h2> {% endif %} {{ title_suffix }} {% block content %} {{ content }} {% endblock %} </div>

block.html.twig:

slide-11
SLIDE 11

Starting to build Starting to build

{% extends "@stable/block/block.html.twig" %} {% block content %} <div class="block-search-form-wrapper"> {{ parent() }} </div> {% endblock %} . ├── my_theme.info.yml └── templates ├── block--search-form-block.html.twig └── page.html.twig

block--search-form-block.html.twig:

slide-12
SLIDE 12

Starting to grow Starting to grow

{% extends "@stable/block/block.html.twig" %} {% block content %} <div class="block-search-form-wrapper"> {{ parent() }} </div> {% endblock %} . ├── my_theme.info.yml └── templates ├── block--search-form-block.html.twig ├── block.html.twig └── page.html.twig

block--search-form-block.html.twig:

slide-13
SLIDE 13

What more do What more do we need? we need?

slide-14
SLIDE 14

Planning for growth Planning for growth

{% extends "block.html.twig" %} {% block content %} <div class="block-search-form-wrapper"> {{ parent() }} </div> {% endblock %} . ├── my_theme.info.yml └── templates ├── block--search-form-block.html.twig ├── block.html.twig └── page.html.twig

block--search-form-block.html.twig:

slide-15
SLIDE 15
  • 1. By template name:
  • 2. By namespace:
  • 3. Full path from Drupal root:

"core/themes/stable/templates/block/block.html.twig"

Referencing other Referencing other Twig templates Twig templates

"@stable/block/block.html.twig" "block.html.twig"

slide-16
SLIDE 16
slide-17
SLIDE 17

Libraries Libraries*

cuddly-slider: version: 1.x css: theme: css/cuddly-slider.css: {} js: js/cuddly-slider.js: {} dependencies:

  • core/jquery

my_theme.libraries.yml:

slide-18
SLIDE 18

Overrides Overrides

libraries-override: classy/base: css: component: css/components/menu.css: false user/drupal.user: false

my_theme.info.yml:

slide-19
SLIDE 19

jQuery Update jQuery Update

libraries-override: core/jquery: js: assets/vendor/jquery/jquery.min.js: js/jquery-5000.js

my_theme.info.yml:

slide-20
SLIDE 20

Your Custom Your Custom Modernizr Build Modernizr Build

libraries-override: core/modernizr: js: assets/vendor/modernizr/modernizr.min.js: js/modernizr.min.js

my_theme.info.yml:

slide-21
SLIDE 21

Extending Extending

libraries-extend: user/drupal.user:

  • my_theme/user

classy/node:

  • my_theme/node

my_theme.info.yml:

slide-22
SLIDE 22
slide-23
SLIDE 23

Remember: Remember: Drupal 8 is not done. Drupal 8 is not done.

slide-24
SLIDE 24

Thanks. Thanks.

@Cottser Twitter: #drupaltwig IRC: #drupal-twig drupaltwig.org