Updated August 17, 2023
Introduction to Drupal 8 Themes
The following article provides an outline for Drupal 8 Themes. Normally themes are one of the most important parts of Drupal that we can see anywhere; they are collections of files that regulate the website’s layout and visual appearance; We use them to see the design in the browser. Themes are used to maintain the structural view of the webpage, and they contain the different components that we need to display, designed by the front-end developer.
When someone visits your Drupal-powered application, the part of Drupal they see when they view any page in their browser is called a theme. A theme is like a layer, similar to a screen that separates your Drupal content from your site visitors. When a page is requested, Drupal assembles the content to be displayed into structured data. The presentation layer then decides how to represent the provided data visually.
Front-end developers create Drupal themes. The term theme or “theme developers” is frequently used. Standard web assets like images, CSS, JavaScript, and YAML files that tell Drupal about the file and features that make up each theme are combined with Drupal-specific templates for creating HTML markup. A Drupal website’s design is determined by its themes. To put a design for their website into action, themes, also known as theme developers, make use of HTML, CSS, JavaScript, and other front-end assets. A collection of files in each theme defines the presentation layer for your application. One of the first places that Drupal site code is usually customized is in the theme, which often is unique to the site it was created.
Key Takeaways
- It provides the flexibility to the developer to create customizable themes as per client requirements.
- Drupal 8 themes provide a digital solution that we can quickly scale whenever we are required.
- Another one of the most important key points is the security of their users.
How to Create Drupal 8 Themes?
Let’s see how to create Drupal 8 themes as follows:
We know Drupal 8 contains the .yml file instead of.INFO file, and it is used to provide the information to the website for theme existence. So first, we need to create the .yml file inside the themes folder, shown in the screenshot below.
In the next step, we need to update the YAML file, which we already created, and make changes per our requirement for a sample, as shown below.
Name: sampledummy
description: This is the first yml file created for demo purposes.
type: theme
core: 8.x
This is the same one we need to add to the YAML file, shown in the screenshot below.
Now we need to visit the Drupal website and check whether the created theme appears or not inside the Drupal section. If we follow all steps correctly, then we can use the custom box for our yml file.
Now we need to remove the Stylesheets from the code because we need to set the new themes as the default theme and navigate the control of the homepage of websites. We know Drupal has different stylesheets, so we need to check carefully. For checking, we need to inspect our source code and see the CSS file, which we need to remove, as shown in the below screenshot.
Also, we need to remove it from the YAML file, so we need to add the parameter shown in the screenshot below.
Now we need to clear the cache, so we need to log in as Drupal admin, go to the configuration, select performance, and click on the Clear all caches button shown in the screenshot below.
For website optimization, we need to uncheck the Aggregate CSS and Aggregate JavaScript file box and Bandwidth Optimization shown in the screenshot below.
In the next step, we need to add the reference of CSS into the .yml file, so create a separate .yml file and add the reference to the original file, as shown in the screenshot below.
Similarly, we can add the JavaScript reference into the yml file per our requirement.
Parameters
Let’s see what parameters we require for the Drupal theme:
Configuration management is built-in with parameters. Consider fully exportable and manageable configuration properties that are dynamic and user-defined.
Examples of applications for parameters include:
- Define a configurable message text and a maximum resource capacity for a particular content type.
- Define the content that should be part of configuration management (such as a parameter that guarantees availability).
- Integer numbers, dates, and data from external HTTP web services can all be automatically incremented with parameters.
- We can manage parameters specific to content types and global parameters for your website. You can use Tokens, ECA, or an API to get to them.
By providing an auto-locking mechanic for used collections, parameters ensure availability. Boundaries of locked assortments can’t be erased through UI as long as they have not been opened once more.
info.yml File
This is the first step towards creating themes, which means first, we need to create an info.yml file inside the root folder. This info.yml file is nothing but a human-readable file with a file name where we store all the required properties of our themes, such as name, version, etc.
For example, we can consider the following screenshot as an example.
Enabling and Disabling in Drupal 8 Themes
Let’s see how we can enable the following:
1. First, we need to login into the Drupal admin panel.
2. In the second step, we need to select the menu shown in the screenshot below.
3. Here, we can see the list of all menus from that; we need to click on the Appearance button as shown below screenshot.
4. Now we get to the main screen of the appearance tab; here, we can see the list of themes; on this page, we can see the enabled themes list on the top. At the bottom, we can see the list of all disabled themes, so find the themes we need to enable and click on them. After clicking, we got two different options such as setting, enable and set default. We use the ‘enabled’ option to enable themes easily. If we want to set a theme as default, we need to click on the ‘set default’ option, as shown in the screenshot below.
Let’s see how we can disable the themes that follow.
1. First, we need to login into the Drupal admin panel.
2. In the second step, we need to select the menu shown in the screenshot below.
3. Here, we can see the list of all menus from which we need to click on the Appearance button, as shown below screenshot.
4. Now we get to the main screen of the appearance tab; here, we can see the list of themes; on this page, we can see all disabled themes listed on the top. At the bottom, we can see the list of all enabled themes, so find the themes we need to disable and click on them. We clicked on the default option, after which it was displayed, and then we clicked on it to disable it, as shown in the screenshot below.
Conclusion
From this article, we can understand Drupal 8 themes. It provides the basic idea and implementation of Drupal 8 themes, and we also saw the representation of the Drupal 8 themes. Additionally, there are numerous pre-built Drupal 8 themes that you can utilize as a base for your own custom theme. You can download these themes from either the third-party website or the official Drupal website.
Recommended Articles
This article is a gist of Drupal 8 Themes. To learn more about the topic, you can refer to these articles –