SlideShare a Scribd company logo
1 of 48
Download to read offline
BUILDING A CUSTOM
THEME IN DRUPAL 8
BASED ON THE CLASSY BASE THEME
Presentation by Anne Tomasevich
INTRODUCTION
This is the part where I talk about myself
Photo by Jessie Gladdek
savaslabs.com
@Savas_Labs
AGENDA
What's changing?
Let's make a theme
Twig basics and debugging
LET'S START FROM THE VERY
BEGINNING
WHAT IS THEMING?
Themes allow you to change the look and
feel of your Drupal site.
- Someone who's good at being very general
WHY WOULD YOU USE DRUPAL 8
NOW?!
And when is it coming out?
WHAT'S CHANGING?
...and how do I, a person who probably doesn't like change, cope with these changes...
WHAT'S NEW IN DRUPAL 8?
Twig, a template engine by SensioLabs
Classy, a new base theme
template.phpbecomes [theme-name].theme. (Dear Drupal
gods, can we please have theme.php?)
WHAT'S NEW IN DRUPAL 8?
Responsive design elements are included by default
Breakpoints can be set and used across modules and themes
WHAT'S NEW IN DRUPAL 8?
LOOK AT ALL THE PRETTY THINGS
WE GET TO USE NOW!!
HTML5
CSS3
Modern jQuery libraries
SMACSS
BEM
Standardized breakpoints
WHAT'S NEW IN DRUPAL 8?
Support for IE8 and below is dropped meaning the use of
jQuery 2.0, HTML5, and CSS3 (including pseudo selectors) are
now supported
CSS:
Far fewer IDs are used
CSS file structure now uses
Default class names follow the format
CSS and JS files are attached to pages differently
SMACSS
BEM
WHAT'S NEW IN DRUPAL 8?
For a more comprehensive list, visit Drupal's change log.
WHY ALL THE CHANGES?
ACCESSIBILITY TO NON-DRUPALERS
Fewer Drupal-specific conventions and more popular, well-
documented frameworks (such as Twig), meaning non-
Drupalers can jump in much more quickly.
D8 themers don’t need to know PHP to whip up a theme.*
* I mean kinda ¯_(ツ)_/¯
WHY ALL THE CHANGES?
SECURITY
Text is automatically escaped in Twig, meaning a lower
chance of XSS attacks.
Template files are more secure since they no longer contain
PHP code.
<?php db_query('DROP TABLE {users}'); ?>
Scary example courtesy of sqndr at d8.sqndr.com.
WHY ALL THE CHANGES?
CURRENT FRAMEWORKS AND TOOLS
Separation of logic from appearance = more modular
(reusable) code
More semantic CSS class names = leaner CSS and a more
readable DOM
A general trend towards more extendable, modular, well-
organized, better-performing code
ANY DISADVANTAGES?
1. Many contributed themes and modules don't having their 8.x
branches ready.
A fun note on the 8.x branch of a popular contrib theme:
This is a development branch. Please note
that this branch is probably severely broken.
It is strongly recommended to wait before
using this branch or even creating issues
regarding it.
ANY DISADVANTAGES?
2. Serious lack of documentation online
Of the documentation that DOES exist, much of it is:
Outdated, and marked as such.
Outdated, and NOT marked as such.
LET'S BUILD THIS THING
WHAT AM I TOTALLY GLOSSING
OVER?
template.php *.theme
Grid framework and CSS architecture
Probably a lot of other things
CREATE A THEME FOLDER
Drupal core now resides in its own folder. Contributed and
custom modules and themes are in the modulesand themes
folders, respectively.
Don't forget to create a customfolder for your custom
theme!
CREATE A .INFO.YML FILE
# mappy.info.yml
name: Mappy
type: theme
description: 'D8 Theme for a basic leaflet site.'
core: 8.x
base theme: classy
libraries:
- mappy/global-styling
- mappy/leaflet
regions:
navbar: 'Top Navigation Bar'
content: Content # required!
sidebar: 'Sidebar'
footer: 'Footer'
[theme-name].infobecomes [theme-name].info.yml
DOT INFO DOT WHAT?
YAML is a data serialization language.
Key-value pairs.
Check out on YAML syntax
before getting started.
And mind your whitespace!
Symfony's excellent writeup
CREATE A .INFO.YML FILE
# mappy.info.yml
name: Mappy
type: theme
description: 'D8 Theme for a basic leaflet site.'
core: 8.x
regions:
navbar: 'Top Navigation Bar'
content: Content # required!
sidebar: 'Sidebar'
footer: 'Footer'
This looks familiar, right?
CLASSY, A NEW BASE THEME
# mappy.info.yml
base theme: classy
In D8, default classes are stripped from Drupal core and
moved into the base theme Classy.
To avoid these default classes, simply don't base your theme
on Classy.
But we want them because BEM is awesome! Check out this
awesome introduction.
LIBRARIES
# mappy.info.yml
libraries:
- mappy/global-styling
- mappy/leaflet
In D8, assets can be added in a few different ways: globally,
per-template, per-page, and more.
All libraries must be defined in your *.libraries.ymlfile.
CREATE A .LIBRARIES.YML FILE
# mappy.libraries.yml
global-styling:
css:
theme:
css/styles.css: {}
leaflet:
css:
theme:
css/leaflet.css: {}
js:
js/leaflet.js: {}
js/map.js: {}
dependencies:
- core/jquery
Note that jQuery is listed as a dependency of the Leaflet library.
Since jQuery is no longer loaded automatically on every page, it
must be explicitly required.
ADDING ASSETS TO YOUR SITE
# mappy.info.yml
libraries:
- mappy/global-styling
- mappy/leaflet
Since this is a small site and we need our libraries on every
page, we're adding them globally.
Visit for more information on methods for adding
assets.
drupal.org
CREATE A .BREAKPOINTS.YML
FILE
# mappy.breakpoints.yml
mappy.mobile:
label: mobile
mediaQuery: '(min-width: 0px)'
weight: 2
multipliers:
- 1x
mappy.narrow:
label: narrow
mediaQuery: 'all and (min-width: 560px) and (max-width: 850px)'
weight: 1
multipliers:
- 1x
mappy.wide:
label: wide
mediaQuery: 'all and (min-width: 851px)'
weight: 0
multipliers:
Ours is stolen adapted from the Bartik theme.
BREAKPOINTS
Once you add a .breakpoints.ymlfile (and uninstall and
reinstall your theme), the breakpoints you've set will be
exposed in the admin UI.
These breakpoints can be used across various modules.
WITH THESE FILES SET UP, WE
NOW HAVE A WORKING CUSTOM
THEME!
TEMPLATE FILES
In our theme's current state, we're using Classy's default
template files.
If we want to override them, it's time to learn some Twig.
If one more person makes a "Gettin' Twiggy with it" joke...
INTRO TO TWIG
is a template engine with syntax similar to Django, Jinja,
and Liquid.
It simplifies template creation with clean syntax and useful
built-in filters, functions, and tags.
In a Drupal template file (now with the extention .html.twig),
anything between curly braces is Twig.
Twig
TWIG DELIMITERS
{{ These }}are for printing content, either explicitly or via
functions
{% These %}are for executing statements
{# These #}are for comments
PRINTING VARIABLES AND
REGIONS
In D7 we render content like so:
<?php print render($page['sidebar']); ?>
Printing variables in D8 is as easy as including them inside
double curly braces:
{# In page--front.html.twig #}
{# Print the sidebar region. #}
{{ page.sidebar }}
PRINTING VARIABLES WITH
SPECIAL CHARACTERS
If a variable name contains special characters, use Twig's
subscript syntax (which will look familiar to seasoned
Drupalers).
{# In page--front.html.twig #}
{# Print the page type. #}
{{ page['#type'] }}
This will come in handy more during debugging.
FILTERS
Twig comes with many that variables are passed
to via the pipe character.
built-in filters
Here's the date filter:
{# Format the post date. #}
{{ post.published|date("Y-m-d") }}
DRUPAL-SPECIFIC FILTERS
Check them out here.
Remember our old friend t()?
{# Run an ARIA label through t() #}
<nav class="tabs" role="navigation" aria-label="{{ 'Tabs'|t }}">
FUNCTIONS
Twig also comes with various that can be used in
double curly braces.
functions
Here's the cycle function doing some very important work:
{% set fruits = ['apple', 'orange', 'banana'] %}
{% for i in 0..10 %}
{{ cycle(fruits, i) }}
{% endfor %}
TAGS
Used for control flow and other fun things.
{# From Bartik's page.html.twig #}
{# If there are tabs, output them. #}
{% if tabs %}
<nav class="tabs" role="navigation" aria-label="{{ 'Tabs'|t }}">
{{ tabs }}
</nav>
{% endif %}
In template files, we’ll use the ifstatement quite often.
GET PSYCHED
Make sure you check out the Twig coding standards!
TWIG DEBUGGING
To enable debug mode and turn off caching, we need to do 3
things:
1. Turn on Twig’s debug mode
2. Turn on Twig auto reload, meaning that Twig templates are
automatically recompiled when the source code is changed
3. Disable Drupal’s render cache
You do NOT need turn off Twig caching - turning on auto reload
is enough.
USE SETTINGS.LOCAL.PHP
1. Copy sites/example.settings.local.phpto
sites/defaultand rename to settings.local.php. Fill out
your local database settings.
2. Uncomment the following at the bottom of
sites/default/settings.php:
if (file_exists(__DIR__ . '/settings.local.php')) {
include __DIR__ . '/settings.local.php';
}
TURN ON DEBUG MODE AND
AUTO RELOAD
Check out settings.local.php
// In settings.local.php
/**
* Enable local development services.
*/
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
This tells us to head over to development.services.yml.
// In sites/development.services.yml
parameters:
twig.config:
debug: true
auto-reload: true
TURN OFF DRUPAL'S RENDER
CACHE
Just kidding, you already did.
// In settings.local.php
/**
* Disable the render cache (this includes the page cache).
*
* This setting disables the render cache by using the Null cache back-end
* defined by the development.services.yml file above.
*
* Do not use this setting until after the site is installed.
*/
$settings['cache']['bins']['render'] = 'cache.backend.null';
DEBUG AWAY
Now you can:
View HTML comments in your browser’s code inspector with
lots of helpful info:
Which theme hook is being implemented
Theme hook suggestions (i.e. how to override the current
theme hook)
Which template file is being output.
Make changes to your source code and simply refresh the
page to see your changes rather than constantly rebuilding
the cache.
DUMP( )
With Twig debugging turned on, we can use the Twig function
dump().
{# In a template file #}
{# Print out all variables on the page. #}
{{ dump() }}
{# Print the page's base path. #}
{{ dump(base_path) }}
EVEN BETTER: KINT( )
Install the Devel and Devel Kint modules to use kint()in the
same way, but with a pretty, expandable array instead.
{# In a template file #}
{# Print out all variables on the page. #}
{{ kint() }}
RESOURCES AND FURTHER
READING
A brilliant blog post about D8 theming (Savas)
D8 theming guide (Sander)
YAML formatting (Symfony)
Intro to BEM (CSS Wizardry)
Adding assets to pages (drupal.org)
Twig documentation (Sensiolabs)
Drupal-specific Twig filters (drupal.org)
Twig coding standards (drupal.org)
Twig debugging and devel (drupalize.me)
QUESTIONS?
@Savas_Labs
savaslabs.com

More Related Content

What's hot

Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeAdolfo Nasol
 
Getting started with drupal 8 code
Getting started with drupal 8 codeGetting started with drupal 8 code
Getting started with drupal 8 codeForum One
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)kuydigital
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentsparkfabrik
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Eugenio Minardi
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingRobert Carr
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) ThemingPINGV
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Emma Jane Hogbin Westby
 
Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Emma Jane Hogbin Westby
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateLaura Scott
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & Moredrubb
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Ryan Price
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designerselliotjaystocks
 
Drupal 8 版型開發變革
Drupal 8 版型開發變革Drupal 8 版型開發變革
Drupal 8 版型開發變革Chris Wu
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Formsdrubb
 
Drupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendDrupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendAcquia
 

What's hot (20)

Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 Theme
 
Getting started with drupal 8 code
Getting started with drupal 8 codeGetting started with drupal 8 code
Getting started with drupal 8 code
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)Drupal theming - a practical approach (European Drupal Days 2015)
Drupal theming - a practical approach (European Drupal Days 2015)
 
Introduction to Drupal (7) Theming
Introduction to Drupal (7) ThemingIntroduction to Drupal (7) Theming
Introduction to Drupal (7) Theming
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) Theming
 
A look at Drupal 7 Theming
A look at Drupal 7 ThemingA look at Drupal 7 Theming
A look at Drupal 7 Theming
 
Design to Theme @ CMSExpo
Design to Theme @ CMSExpoDesign to Theme @ CMSExpo
Design to Theme @ CMSExpo
 
Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009Learning PHP for Drupal Theming, DC Chicago 2009
Learning PHP for Drupal Theming, DC Chicago 2009
 
Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010Intro to Theming Drupal, FOSSLC Summer Camp 2010
Intro to Theming Drupal, FOSSLC Summer Camp 2010
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb update
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & More
 
Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011Drupal Theme Development - DrupalCon Chicago 2011
Drupal Theme Development - DrupalCon Chicago 2011
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designers
 
Drupal 8 版型開發變革
Drupal 8 版型開發變革Drupal 8 版型開發變革
Drupal 8 版型開發變革
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
Drupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of FrontendDrupal 8 Theme System: The Backend of Frontend
Drupal 8 Theme System: The Backend of Frontend
 

Viewers also liked

Converting Static Html To Drupal Theme
Converting Static Html To Drupal ThemeConverting Static Html To Drupal Theme
Converting Static Html To Drupal ThemeRyan Cross
 
Drupal 8: TWIG Template Engine
Drupal 8:  TWIG Template EngineDrupal 8:  TWIG Template Engine
Drupal 8: TWIG Template Enginedrubb
 
Responsive design with flexbox
Responsive design with flexboxResponsive design with flexbox
Responsive design with flexboxMario Hernandez
 
Building your first d8 theme
Building your first d8 themeBuilding your first d8 theme
Building your first d8 themeMario Hernandez
 
Blocks & layouts szeged
Blocks & layouts szegedBlocks & layouts szeged
Blocks & layouts szegeddasjo
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Rene Bakx
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of TwigBrandon Kelly
 
UX design for every screen
UX design for every screenUX design for every screen
UX design for every screenFour Kitchens
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme KickstartPeter
 
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeSuzanne Dergacheva
 
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming HeadachesSrijan Technologies
 
Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Acquia
 
Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!tedbow
 
Drupal 101: Tips and Tricks for Troubleshooting Drupal
Drupal 101: Tips and Tricks for Troubleshooting DrupalDrupal 101: Tips and Tricks for Troubleshooting Drupal
Drupal 101: Tips and Tricks for Troubleshooting DrupalAcquia
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Acquia
 

Viewers also liked (17)

Converting Static Html To Drupal Theme
Converting Static Html To Drupal ThemeConverting Static Html To Drupal Theme
Converting Static Html To Drupal Theme
 
Drupal 8: TWIG Template Engine
Drupal 8:  TWIG Template EngineDrupal 8:  TWIG Template Engine
Drupal 8: TWIG Template Engine
 
Responsive design with flexbox
Responsive design with flexboxResponsive design with flexbox
Responsive design with flexbox
 
Building your first d8 theme
Building your first d8 themeBuilding your first d8 theme
Building your first d8 theme
 
Blocks & layouts szeged
Blocks & layouts szegedBlocks & layouts szeged
Blocks & layouts szeged
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
 
UX design for every screen
UX design for every screenUX design for every screen
UX design for every screen
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme Kickstart
 
A Custom Drupal Theme in 40 Minutes
A Custom Drupal Theme in 40 MinutesA Custom Drupal Theme in 40 Minutes
A Custom Drupal Theme in 40 Minutes
 
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
 
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
[Srijan Wednesday Webinars] Drupal 8: Goodbye to 10 Years of Theming Headaches
 
Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8
 
Designing with Drupal 8
Designing with Drupal 8Designing with Drupal 8
Designing with Drupal 8
 
Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!Entities, Bundles, and Fields: You need to understand this!
Entities, Bundles, and Fields: You need to understand this!
 
Drupal 101: Tips and Tricks for Troubleshooting Drupal
Drupal 101: Tips and Tricks for Troubleshooting DrupalDrupal 101: Tips and Tricks for Troubleshooting Drupal
Drupal 101: Tips and Tricks for Troubleshooting Drupal
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
 

Similar to Building a Custom Theme in Drupal 8

Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend developmentsparkfabrik
 
Display Suite: A Themers Perspective
Display Suite: A Themers PerspectiveDisplay Suite: A Themers Perspective
Display Suite: A Themers PerspectiveMediacurrent
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practicesSynapseindiappsdevelopment
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in DrupalWingston
 
Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with FeaturesNuvole
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Demystifying drupal 7 theming
Demystifying drupal 7 themingDemystifying drupal 7 theming
Demystifying drupal 7 themingAnthony Ogbonna
 
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...DrupalCamp Kyiv
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To DrupalLauren Roth
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
CivicActions Drupal Directory Structure
CivicActions Drupal Directory StructureCivicActions Drupal Directory Structure
CivicActions Drupal Directory StructureGregory Heller
 
Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricksaaroncouch
 
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)Nuvole
 
Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8Eugenio Minardi
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Angela Byron
 

Similar to Building a Custom Theme in Drupal 8 (20)

Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
 
Display Suite: A Themers Perspective
Display Suite: A Themers PerspectiveDisplay Suite: A Themers Perspective
Display Suite: A Themers Perspective
 
Drupal
DrupalDrupal
Drupal
 
SynapseIndia drupal presentation on drupal best practices
SynapseIndia drupal  presentation on drupal best practicesSynapseIndia drupal  presentation on drupal best practices
SynapseIndia drupal presentation on drupal best practices
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
Building and Maintaining a Distribution in Drupal 7 with Features
Building and Maintaining a  Distribution in Drupal 7 with FeaturesBuilding and Maintaining a  Distribution in Drupal 7 with Features
Building and Maintaining a Distribution in Drupal 7 with Features
 
Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Demystifying drupal 7 theming
Demystifying drupal 7 themingDemystifying drupal 7 theming
Demystifying drupal 7 theming
 
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...
Anton Faibyshev - Drupal 8: lazy builder. What we need to build a house - we ...
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
CivicActions Drupal Directory Structure
CivicActions Drupal Directory StructureCivicActions Drupal Directory Structure
CivicActions Drupal Directory Structure
 
Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricks
 
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
Configuration Management in Drupal 8: A preview (DrupalDays Milano 2014)
 
Drupal theme development
Drupal theme developmentDrupal theme development
Drupal theme development
 
Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8Gestione della configurazione in Drupal 8
Gestione della configurazione in Drupal 8
 
Drupal Theme Development
Drupal Theme DevelopmentDrupal Theme Development
Drupal Theme Development
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 

Recently uploaded

Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Onlineanilsa9823
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 

Recently uploaded (20)

Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 

Building a Custom Theme in Drupal 8

  • 1. BUILDING A CUSTOM THEME IN DRUPAL 8 BASED ON THE CLASSY BASE THEME Presentation by Anne Tomasevich
  • 2. INTRODUCTION This is the part where I talk about myself Photo by Jessie Gladdek savaslabs.com @Savas_Labs
  • 3. AGENDA What's changing? Let's make a theme Twig basics and debugging
  • 4. LET'S START FROM THE VERY BEGINNING WHAT IS THEMING? Themes allow you to change the look and feel of your Drupal site. - Someone who's good at being very general
  • 5. WHY WOULD YOU USE DRUPAL 8 NOW?! And when is it coming out?
  • 6. WHAT'S CHANGING? ...and how do I, a person who probably doesn't like change, cope with these changes...
  • 7. WHAT'S NEW IN DRUPAL 8? Twig, a template engine by SensioLabs Classy, a new base theme template.phpbecomes [theme-name].theme. (Dear Drupal gods, can we please have theme.php?)
  • 8. WHAT'S NEW IN DRUPAL 8? Responsive design elements are included by default Breakpoints can be set and used across modules and themes
  • 9. WHAT'S NEW IN DRUPAL 8? LOOK AT ALL THE PRETTY THINGS WE GET TO USE NOW!! HTML5 CSS3 Modern jQuery libraries SMACSS BEM Standardized breakpoints
  • 10. WHAT'S NEW IN DRUPAL 8? Support for IE8 and below is dropped meaning the use of jQuery 2.0, HTML5, and CSS3 (including pseudo selectors) are now supported CSS: Far fewer IDs are used CSS file structure now uses Default class names follow the format CSS and JS files are attached to pages differently SMACSS BEM
  • 11. WHAT'S NEW IN DRUPAL 8? For a more comprehensive list, visit Drupal's change log.
  • 12. WHY ALL THE CHANGES? ACCESSIBILITY TO NON-DRUPALERS Fewer Drupal-specific conventions and more popular, well- documented frameworks (such as Twig), meaning non- Drupalers can jump in much more quickly. D8 themers don’t need to know PHP to whip up a theme.* * I mean kinda ¯_(ツ)_/¯
  • 13. WHY ALL THE CHANGES? SECURITY Text is automatically escaped in Twig, meaning a lower chance of XSS attacks. Template files are more secure since they no longer contain PHP code. <?php db_query('DROP TABLE {users}'); ?> Scary example courtesy of sqndr at d8.sqndr.com.
  • 14. WHY ALL THE CHANGES? CURRENT FRAMEWORKS AND TOOLS Separation of logic from appearance = more modular (reusable) code More semantic CSS class names = leaner CSS and a more readable DOM A general trend towards more extendable, modular, well- organized, better-performing code
  • 15. ANY DISADVANTAGES? 1. Many contributed themes and modules don't having their 8.x branches ready. A fun note on the 8.x branch of a popular contrib theme: This is a development branch. Please note that this branch is probably severely broken. It is strongly recommended to wait before using this branch or even creating issues regarding it.
  • 16. ANY DISADVANTAGES? 2. Serious lack of documentation online Of the documentation that DOES exist, much of it is: Outdated, and marked as such. Outdated, and NOT marked as such.
  • 18. WHAT AM I TOTALLY GLOSSING OVER? template.php *.theme Grid framework and CSS architecture Probably a lot of other things
  • 19. CREATE A THEME FOLDER Drupal core now resides in its own folder. Contributed and custom modules and themes are in the modulesand themes folders, respectively. Don't forget to create a customfolder for your custom theme!
  • 20. CREATE A .INFO.YML FILE # mappy.info.yml name: Mappy type: theme description: 'D8 Theme for a basic leaflet site.' core: 8.x base theme: classy libraries: - mappy/global-styling - mappy/leaflet regions: navbar: 'Top Navigation Bar' content: Content # required! sidebar: 'Sidebar' footer: 'Footer' [theme-name].infobecomes [theme-name].info.yml
  • 21. DOT INFO DOT WHAT? YAML is a data serialization language. Key-value pairs. Check out on YAML syntax before getting started. And mind your whitespace! Symfony's excellent writeup
  • 22. CREATE A .INFO.YML FILE # mappy.info.yml name: Mappy type: theme description: 'D8 Theme for a basic leaflet site.' core: 8.x regions: navbar: 'Top Navigation Bar' content: Content # required! sidebar: 'Sidebar' footer: 'Footer' This looks familiar, right?
  • 23. CLASSY, A NEW BASE THEME # mappy.info.yml base theme: classy In D8, default classes are stripped from Drupal core and moved into the base theme Classy. To avoid these default classes, simply don't base your theme on Classy. But we want them because BEM is awesome! Check out this awesome introduction.
  • 24. LIBRARIES # mappy.info.yml libraries: - mappy/global-styling - mappy/leaflet In D8, assets can be added in a few different ways: globally, per-template, per-page, and more. All libraries must be defined in your *.libraries.ymlfile.
  • 25. CREATE A .LIBRARIES.YML FILE # mappy.libraries.yml global-styling: css: theme: css/styles.css: {} leaflet: css: theme: css/leaflet.css: {} js: js/leaflet.js: {} js/map.js: {} dependencies: - core/jquery Note that jQuery is listed as a dependency of the Leaflet library. Since jQuery is no longer loaded automatically on every page, it must be explicitly required.
  • 26. ADDING ASSETS TO YOUR SITE # mappy.info.yml libraries: - mappy/global-styling - mappy/leaflet Since this is a small site and we need our libraries on every page, we're adding them globally. Visit for more information on methods for adding assets. drupal.org
  • 27. CREATE A .BREAKPOINTS.YML FILE # mappy.breakpoints.yml mappy.mobile: label: mobile mediaQuery: '(min-width: 0px)' weight: 2 multipliers: - 1x mappy.narrow: label: narrow mediaQuery: 'all and (min-width: 560px) and (max-width: 850px)' weight: 1 multipliers: - 1x mappy.wide: label: wide mediaQuery: 'all and (min-width: 851px)' weight: 0 multipliers: Ours is stolen adapted from the Bartik theme.
  • 28. BREAKPOINTS Once you add a .breakpoints.ymlfile (and uninstall and reinstall your theme), the breakpoints you've set will be exposed in the admin UI. These breakpoints can be used across various modules.
  • 29. WITH THESE FILES SET UP, WE NOW HAVE A WORKING CUSTOM THEME!
  • 30. TEMPLATE FILES In our theme's current state, we're using Classy's default template files. If we want to override them, it's time to learn some Twig. If one more person makes a "Gettin' Twiggy with it" joke...
  • 31. INTRO TO TWIG is a template engine with syntax similar to Django, Jinja, and Liquid. It simplifies template creation with clean syntax and useful built-in filters, functions, and tags. In a Drupal template file (now with the extention .html.twig), anything between curly braces is Twig. Twig
  • 32. TWIG DELIMITERS {{ These }}are for printing content, either explicitly or via functions {% These %}are for executing statements {# These #}are for comments
  • 33. PRINTING VARIABLES AND REGIONS In D7 we render content like so: <?php print render($page['sidebar']); ?> Printing variables in D8 is as easy as including them inside double curly braces: {# In page--front.html.twig #} {# Print the sidebar region. #} {{ page.sidebar }}
  • 34. PRINTING VARIABLES WITH SPECIAL CHARACTERS If a variable name contains special characters, use Twig's subscript syntax (which will look familiar to seasoned Drupalers). {# In page--front.html.twig #} {# Print the page type. #} {{ page['#type'] }} This will come in handy more during debugging.
  • 35. FILTERS Twig comes with many that variables are passed to via the pipe character. built-in filters Here's the date filter: {# Format the post date. #} {{ post.published|date("Y-m-d") }}
  • 36. DRUPAL-SPECIFIC FILTERS Check them out here. Remember our old friend t()? {# Run an ARIA label through t() #} <nav class="tabs" role="navigation" aria-label="{{ 'Tabs'|t }}">
  • 37. FUNCTIONS Twig also comes with various that can be used in double curly braces. functions Here's the cycle function doing some very important work: {% set fruits = ['apple', 'orange', 'banana'] %} {% for i in 0..10 %} {{ cycle(fruits, i) }} {% endfor %}
  • 38. TAGS Used for control flow and other fun things. {# From Bartik's page.html.twig #} {# If there are tabs, output them. #} {% if tabs %} <nav class="tabs" role="navigation" aria-label="{{ 'Tabs'|t }}"> {{ tabs }} </nav> {% endif %} In template files, we’ll use the ifstatement quite often.
  • 39. GET PSYCHED Make sure you check out the Twig coding standards!
  • 40. TWIG DEBUGGING To enable debug mode and turn off caching, we need to do 3 things: 1. Turn on Twig’s debug mode 2. Turn on Twig auto reload, meaning that Twig templates are automatically recompiled when the source code is changed 3. Disable Drupal’s render cache You do NOT need turn off Twig caching - turning on auto reload is enough.
  • 41. USE SETTINGS.LOCAL.PHP 1. Copy sites/example.settings.local.phpto sites/defaultand rename to settings.local.php. Fill out your local database settings. 2. Uncomment the following at the bottom of sites/default/settings.php: if (file_exists(__DIR__ . '/settings.local.php')) { include __DIR__ . '/settings.local.php'; }
  • 42. TURN ON DEBUG MODE AND AUTO RELOAD Check out settings.local.php // In settings.local.php /** * Enable local development services. */ $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'; This tells us to head over to development.services.yml. // In sites/development.services.yml parameters: twig.config: debug: true auto-reload: true
  • 43. TURN OFF DRUPAL'S RENDER CACHE Just kidding, you already did. // In settings.local.php /** * Disable the render cache (this includes the page cache). * * This setting disables the render cache by using the Null cache back-end * defined by the development.services.yml file above. * * Do not use this setting until after the site is installed. */ $settings['cache']['bins']['render'] = 'cache.backend.null';
  • 44. DEBUG AWAY Now you can: View HTML comments in your browser’s code inspector with lots of helpful info: Which theme hook is being implemented Theme hook suggestions (i.e. how to override the current theme hook) Which template file is being output. Make changes to your source code and simply refresh the page to see your changes rather than constantly rebuilding the cache.
  • 45. DUMP( ) With Twig debugging turned on, we can use the Twig function dump(). {# In a template file #} {# Print out all variables on the page. #} {{ dump() }} {# Print the page's base path. #} {{ dump(base_path) }}
  • 46. EVEN BETTER: KINT( ) Install the Devel and Devel Kint modules to use kint()in the same way, but with a pretty, expandable array instead. {# In a template file #} {# Print out all variables on the page. #} {{ kint() }}
  • 47. RESOURCES AND FURTHER READING A brilliant blog post about D8 theming (Savas) D8 theming guide (Sander) YAML formatting (Symfony) Intro to BEM (CSS Wizardry) Adding assets to pages (drupal.org) Twig documentation (Sensiolabs) Drupal-specific Twig filters (drupal.org) Twig coding standards (drupal.org) Twig debugging and devel (drupalize.me)