24
The Drupal 8 The Drupal 8 Theming Experience Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16

The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

The Drupal 8 The Drupal 8 Theming ExperienceTheming Experience

Scott Reeves (Cottser)

bit.ly/d8txdca16

Page 2: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Scott ReevesScott ReevesDrupal 8 theme systemand Stable (co-)maintainer Provisional Drupal 8 corecommitter Team Lead @ Digital Echidna Former child pilot

Page 3: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

TX (Themer Experience)TX (Themer Experience)

DX (Developer Experience)DX (Developer Experience)

Page 4: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

What we'll coverWhat we'll cover

Core base themes

The without filter

Twig theme registry loader

Working with libraries

Page 5: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Two main campsTwo main camps

Sensible ⅔ Clean ⅓

Use Classy Use Stable

base theme: classy

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

Page 6: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Power to thePower to thetemplatestemplates**{% 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) }}>

Page 7: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Additive vs.Additive vs.SubtractiveSubtractive

Page 8: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

{{ 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 wantwhen you want

Page 9: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Referencing otherReferencing otherTwig templatesTwig templates

1. By namespace:

2. Full path from Drupal root:

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

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

Page 10: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Twig blocksTwig 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:

Page 11: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Starting to buildStarting 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:

Page 12: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Starting to growStarting 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:

Page 13: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

What more doWhat more dowe need?we need?

Page 14: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Planning for growthPlanning 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:

Page 15: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

1. By template name:

2. By namespace:

3. Full path from Drupal root:

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

Referencing otherReferencing otherTwig templatesTwig templates

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

"block.html.twig"

Page 16: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional
Page 17: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

LibrariesLibraries**

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

my_theme.libraries.yml:

Page 18: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

OverridesOverrides

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

my_theme.info.yml:

Page 19: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

jQuery UpdatejQuery Update

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

my_theme.info.yml:

Page 20: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Your CustomYour CustomModernizr BuildModernizr Build

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

my_theme.info.yml:

Page 21: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

ExtendingExtending

libraries-extend: user/drupal.user: - my_theme/user classy/node: - my_theme/node

my_theme.info.yml:

Page 22: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional
Page 23: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

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

Page 24: The Drupal 8 Theming Experience...The Drupal 8 Theming Experience Scott Reeves (Cottser) bit.ly/d8txdca16 Scott Reeves Drupal 8 theme system and Stable (co-)maintainer Provisional

Thanks.Thanks.

@Cottser

Twitter: #drupaltwigIRC: #drupal-twig

drupaltwig.org