Hands-On Theming
GuideTheming Cheat Sheet
GuideTheming Drupal Sites
CourseLike most output in Drupal, Views relies on Twig templates for a significant amount of its rendering. In this tutorial we'll identify where you can find the default Views templates within your file system, what the common templates are for, and how to name your templates so that they are applied to specific views.
By the end of this tutorial, you should be able to:
- Identify where to find default views templates
- Understand which templates apply to what part of a view
- Get a sense of the template suggestions and how to use them to limit where your custom templates are applied
- Identify a view's machine name
- Identify a display's machine name
- Identify a field's machine name
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about theming based on official releases of Drupal 8, view tutorials in our Drupal 8 Theming Guide.
[# card #]
nid: 2512
title: D8 Theming series
[# endcard #]
This presentation outlines some of the major changes to the way that themes are built in Drupal 8 and is intended to help you generate a list of the things you're going to need to know in order to start making awesome Drupal 8 themes. A lot has changed, and there are a lot of new things to learn. However, one of the primary focuses has been on making the theme layer easier to understand, and easier to get started with.
Almost every aspect of the theming layer has been touched in one way or another during the Drupal 8 development cycle. We think some of the important ones to learn about are:
- How Drupal 8 makes the theme layer easier to understand
- Changes to help make Drupal responsive and mobile friendly
- The adoption of current best practices for HTML5, CSS, and JavaScript
- The addition of a new template engine based on Twig
After watching this presentation you should have a better understanding of the things you'll need to learn in order to create themes in Drupal 8 and where you might need to brush up.
Additional resources
- Drupal 8 Theming Guide (Drupalize.Me)
- Changes for themers
- Twig Theming video tutorial series
- Acquia's Ultimate Guide to Drupal 8: Episode 5 - Front-End Developer Improvements
- DrupalCorn Presentation by Marc Drummond: Building a Drupal 8 theme with new fangled awesomeness
- DrupalCon Sydney Presentation by Jen Lampton: Twig, and the New Theme Layer in Drupal 8
- DrupalCon Austin Presentation by Scott Reeves and Joël Pittet: Drupal 8 Theme System: hook_theme to Twig Template
One of the challenges that comes with Layout Builder is increased complexity of front-end development. Layout Builder offers site administrators increased flexibility regarding the placement and use of fields and blocks; a theme developer needs to account for this. Depending on how Layout Builder is used, this could mean a small number of new combinations, or virtually infinite combinations. Therefore, predicting and theming all of these combinations becomes a difficult but necessary task in order to ensure maintainability and overall design consistency.
In this tutorial we'll look at some things we've found helpful to consider when theming Layout Builder including:
- Design, and theme, atomic components
- Limit the number of possible combinations of fields by using entity view modes
- Handle edge cases
By the end of this tutorial you should have a better understanding of how using Layout Builder can impact theme development, and how to account for it.
By default, individual forms in Drupal are not output using Twig template files. It's possible to associate a form with a Twig template file by creating a new theme hook, and then referencing that theme hook from the $form
array that defines the form. Doing so allows theme developers to customize the layout of the elements in the form using HTML and CSS.
This is useful when you want to change the layout of the entire form. For example, putting the elements into 2 columns. If you want to change individual elements in the form, you can often do so by overriding element specific Twig template files.
In this tutorial, we'll:
- Learn how to create a new theme hook that can be used to theme an element in a render array.
- Associate the
$form
we want to theme with the new theme hook we created. - Create a Twig template file for the theme hook that will allow us to lay out the form elements using custom HTML.
By the end of this tutorial, you should be able to associate a Twig template file with any form in Drupal, so that you can customize its layout using HTML and CSS.
Set up a local development environment to practice Drupal theme development. In order to practice theme development, either on your own or following our Hands-On: Theming guide, you'll need a Drupal site up and running on your computer.
By the end of this tutorial, you should be able to:
- Install Drupal on your computer so you can modify files with a code editor of your choice.
- Generate dummy content so that you have different kinds of pages to theme.
Twig is the default template engine for Drupal. If you want to make changes to the markup that Drupal outputs you're going to need to know at least some Twig. In this tutorial, we will outline the role that Twig now plays in Drupal, how Twig impacts the theming experience, and where to find additional resources for learning Twig.
At the end of this lesson, you'll be able to:
- Describe the role that Twig plays in creating Drupal themes
- Explain how Twig impacts the theming experience in Drupal
- Locate additional resources for learning Twig
This video was part of a series of presentations produced in anticipation of Drupal 8's official release. For information about multilingual sites based on official releases of Drupal 8, take a look at our Multilingual sites topic.
[# card #]
nid: 2925
title: Multilingual sites topic
[# endcard #]
This presentation outlines some of the major changes to the Drupal core multilingual system. A lot of features that were in contributed modules have been rolled into core, and a number of existing multilingual features have been greatly improved. There are a lot of cool new things to get up to speed with. In this video, we'll review:
- New and obsolete modules
- UI changes
- Developer changes
After watching this presentation you should have a better understanding of the things you'll need to learn to get up to speed with the new multilingual features in Drupal 8, including things to watch for on the module development and theming sides.
Additional resources
Drupal 8 Multilingual Initiative site
Gábor Hojtsy's Multilingual Changes Summary (PDF)
Core Themes: Bartik
FreeBartik is a core theme in Drupal. As a default theme for Drupal, it serves as an instructive example of a well-developed responsive theme. In this tutorial, we'll tour and explore Bartik, identify its primary features, and explain the use case for the Bartik theme and what you can learn from it.
Learn Drupal
GuideWhat Is a Theme?
FreeThemes are the part of Drupal that you, and anyone else visiting your Drupal powered application, see when they view any page in their browser. You can think of a theme as a layer, kind of like a screen, that exists between your Drupal content and the users of your site. Whenever a page is requested Drupal does the work of assembling the content to display into structured data which is then handed off to the presentation layer to determine how to visually represent the data provided.
Drupal themes are created by front-end developer. Frequently referred to as themers, or theme developers. Themes consist of standard web assets like CSS, JavaScript, and images, combined with Drupal-specific templates for generating HTML markup, and YAML files for telling Drupal about the file and features that make up each individual theme.
In this tutorial we'll:
- Explain what a Drupal theme is.
- Explain the role of a Drupal themer in the process of building a Drupal site.
- Get a high level overview of the types of files/code that themes are made of.
By the end of this tutorial you should be able to explain what a Drupal theme is, and the kind of work a Drupal theme developer will be expected to do.