Skip to content
  • LinkedIn
  • Twitter
  • Facebook

Desssigner.in

Aryan Srivastava | Adobe Commerce Certified Developer | Magento Tutor

  • Home
  • About Me
  • Contact
  • Toggle search form
Theme-Concept-in-Magento-2

Theme Concept in Magento 2

Posted on June 15, 2021August 26, 2021 By Aryan Srivastava No Comments on Theme Concept in Magento 2

E-commerce plays a very important role in our life, especially in this Covid-19 Pandemic. As we all know, it’s not safe going out for purchasing essential items for us. In that case, many vendors are offering online purchases for our goodwill. Magento is one of the best open-source platforms for eCommerce. This gives users great opportunities to control the look and functionality of the storefront. This provides many tools and features like Marketing, Search Engine Optimization ( SEO ), Catalog Management, etc. The best part is Theme Concept in Magento 2.

Magento 2 is a better and enhanced version of Magento.

Let’s Continue to customize our storefront:

What is the Theme in Magento?

The theme in Magento 2 is responsible for the look and feel of the frontend as well as the backend. They use a combination of PHP, XML, HTML, CSS, and JavaScript to achieve the desired look. Themes override or extend existing PHP, HTML, CSS, and JavaScript while providing extra functionality.

Magento 2 provides us predefined theme i.e,“ Luma” and “Blank”. Magento gives us the option to create a new theme for our store or we can also inherit one from Luma and Blank.


How to create a theme in Magento?

We are going to learn how to create new theme based on “Magento Luma”.

For creating a new theme based on “Magento Blank” or “Magento Luma”, we have to create a folder for a theme. Let’s discuss folder structure:

app/design/frontend/
├── <Vendor>/
│ │ ├──...<theme>/
│ │ │ ├── ...
│ │ │ ├── ...

Here,

<vendor> is the name of the vendor or company who is providing that particular theme.

<theme> is the name of the theme.

For example :

<vendor> => Tutorial

<theme> => Simple

Now, folder will be :

app/design/frontend/
├── Tutorial/
│   │   ├──...Simple/
│   │   │   ├── ...
│   │   │   ├── ...

Within the above folder, we will create the needed file:

  1. theme.xml
  2. registration.php

These are required files for creating a theme and there is also one optional file i.e, composer.json file.

Declare theme in theme.xml file :

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Tutorial Simple</title>
<parent>Magento/luma</parent> 
</theme>

Here,

<title> is the name of theme

<parent> is parent theme .

and also we can add theme preview image in theme.xml file.

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Tutorial Simple</title>
<parent>Magento/luma</parent>
<media>
<preview_image>media/preview.jpg</preview_image> 
</media>
</theme>

Register theme in Magento System :

To register our theme in the system, we have to add a registration.php file in theme directory with the following code :

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Tutorial/Simple, __DIR__);

Create composer.json ( optional ) :

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

{
"name": "Tutorial/Simple",
"description": "N/A",
"config": {
"sort-packages": true
},
"require": {
"php": "~7.2.0||~7.3.0",
"magento/framework": "*",
"magento/theme-frontend-blank": "*"
},
"type": "magento2-theme",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
]
}
}

Configure images of the storefront :

Product image sizes and other properties used on the storefront are configured in a view.xml configuration file. It is required for a theme but is optional if exists in the parent theme.

Configure all storefront product image sizes in view.xml file. For example, you can make the category grid view product images square by specifying a size of 250 x 250 pixels:

<image id="category_page_grid" type="small_image">
<width>250</width>
<height>250</height>
</image>

For more detail, click here

Create directories for static files :

Theme will likely contain several types of static files:

  • Styles
  • Fonts
  • JavaScript
  • Images
app/design/frontend/Tutorial/Simple/
├── web/
│ ├── css/
│ │ ├── source/ 
│ ├── fonts/
│ ├── images/
│ ├── js/

The structure of the theme will be like this:

app/design/frontend/Tutorial/
├── Simple/
│   ├── etc/
│   │   ├── view.xml
│   ├── web/
│   │   ├── css/
│   │     ├── source/ 
│   |   ├── fonts/
│   |   ├── images/
│   |   ├── js/
│   ├── registration.php
│   ├── theme.xml
│   ├── composer.json

Once above steps are completed, we need to execute setup: upgrade command.

$ php bin/magento setup:upgrade

After executing the upgrade command, the theme will register in our database. You can check your theme under “theme table” in the database.

In above steps we have successfully created theme for our storefront but we have to configure theme for storefront from Magento Admin:

Login to Magento Admin > Content > Design > Configuration > click on edit > Default Theme > Under applied theme dropdown select your theme > Save Configuration

After that, we need to clear Magento cache

$ php bin/magento cache:flush

Now, we have successfully applied new created theme on our storefront.

Hope this article helped you to create a theme. If you have any queries, you can ask me directly over email at aryansrivastavadesssigner@gmail.com or contact me here.

If you like this article, you can buy me a cup of coffee Buy me a Coffee.

Reference Links :

  1. https://devdocs.magento.com


Post Views: 368
Magento, Magento Theme, Magento2 Tags:Frontend, Magento2, Theme, Tutorial

Post navigation

Next Post: Layout Overview in Magento 2

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Command list Customer Dashboard Custom Module File override Frontend How to Layout Logout link Magento Magento2 Magento2 Cheat Sheet Magento Tutorial Product Page Theme Tutorial View.xml

CERTIFICATION DIRECTORY

Adobe Commerce Front-End Developer

Adobe Certified Professional - Adobe Commerce Front-End Developer

Adobe Certified Expert-Adobe Commerce Front-End Developer

Copyright © 2023 Desssigner.in.

Powered by PressBook WordPress theme

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT