Theme File Structure
Theme Directory Structure
Magento 2 themes reside in app/design/frontend/:
app/design/frontend/
└── Vendor/
└── ThemeName/
├── theme.xml
├── registration.php
├── web/
│ ├── css/
│ │ └── source/
│ │ └── _extend.less
│ ├── js/
│ │ └── custom.js
│ ├── images/
│ │ └── logo.svg
│ └── fonts/
│ └── custom-font.woff2
├── Magento_Catalog/
│ └── templates/
│ └── product/
│ └── list.phtml
├── media/
│ └── preview.jpg
└── i18n/
├── en_US.csv
└── fr_FR.csv
Vendor/Theme Naming
- Vendor: Your company or namespace (e.g.,
Amazon,Google) - Theme: Theme name (e.g.,
Prep,Storefront) - Combined:
Amazon_Prep - Directory:
app/design/frontend/Amazon/Prep/
Key Files
| File | Purpose |
|---|---|
theme.xml |
Theme configuration (parent, layout, etc.) |
registration.php |
Registers theme with Magento |
web/ |
Static assets (CSS, JS, images, fonts) |
Vendor_Module/ |
Module-specific template overrides |
media/ |
Theme preview image |
i18n/ |
Translation files |
theme.xml Configuration
Basic theme.xml
<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/theme.xsd">
<title>Amazon Prep Theme</title>
<parent>Magento/luma</parent>
<media>
<preview_image>media/preview.jpg</preview_image>
</media>
</theme>
theme.xml Elements
| Element | Required | Description |
|---|---|---|
<title> |
Yes | Display name in admin |
<parent> |
No | Parent theme for inheritance |
<media> |
No | Theme preview image |
Without Parent (Standalone Theme)
<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/theme.xsd">
<title>Custom Standalone Theme</title>
</theme>
With Custom Layout
<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/theme.xsd">
<title>Amazon Prep Theme</title>
<parent>Magento/blank</parent>
<layout>1column</layout>
</theme>
The <layout> element sets the default layout for all pages using this theme.
registration.php
Basic registration.php
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::THEME,
'frontend/Amazon/Prep',
__DIR__
);
How It Works
- Magento scans
app/design/frontend/*/forregistration.phpfiles - Each file registers the theme in the component registry
- Theme becomes available in admin under Content → Design → Themes
- Theme ID format:
frontend/Vendor/Theme
Registration After Theme Creation
After creating theme.xml and registration.php:
# Register the theme
bin/magento setup:upgrade
# Verify registration
bin/magento theme:list
Unregistering a Theme
// In registration.php, just delete the theme directory
// Then run:
bin/magento setup:upgrade
bin/magento cache:clean
Multiple Themes
Each theme has its own registration:
app/design/frontend/Amazon/Prep/
├── registration.php (frontend/Amazon/Prep)
app/design/frontend/Amazon/PrepKids/
└── registration.php (frontend/Amazon/PrepKids)
Fallback Mechanism
How Fallback Works
Magento uses a fallback chain to resolve files:
Custom Theme → Parent Theme → Blank Theme → Magento Core
Visual Fallback Chain
Amazon/Prep (custom)
↓ fallback
Magento/luma
↓ fallback
Magento/blank
↓ fallback
Magento/core (base)
File Resolution Example
When loading Magento_Catalog::product/list.phtml:
- Check:
app/design/frontend/Amazon/Prep/Magento_Catalog/templates/product/list.phtml - Check:
app/design/frontend/Magento/luma/Magento_Catalog/templates/product/list.phtml - Check:
app/design/frontend/Magento/blank/Magento_Catalog/templates/product/list.phtml - Use:
vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
Static Asset Fallback
For CSS/JS/images:
pub/static/frontend/Amazon/Prep/en_US/css/source/_extend.lesspub/static/frontend/Magento/luma/en_US/css/source/_extend.lesspub/static/frontend/Magento/blank/en_US/css/source/_extend.lessvendor/magento/theme-frontend-blank/web/css/source/_extend.less
Fallback Configuration
# Check current theme
bin/magento dev:theme:list
# View fallback chain
bin/magento dev:theme:show-fallback Amazon/Prep
Important Notes
- Fallback only works for files, not for entire templates
- Your theme files override parent theme files
- Static files are published to
pub/static/during deployment
Quiz
1. Where are Magento 2 themes stored?
2. What is the fallback order for theme files?
3. What PHP function registers a theme?
Flashcards
Question
Where are themes located?
Click to reveal answer
Answer
app/design/frontend/Vendor/ThemeName/
Question
What is theme.xml used for?
Click to reveal answer
Answer
Theme configuration including title, parent theme, and layout settings
Question
What does registration.php do?
Click to reveal answer
Answer
Registers the theme with Magento's component registry
Question
What is the fallback mechanism?
Click to reveal answer
Answer
File resolution chain: Custom → Parent → Blank → Core
Question
How do you list all registered themes?
Click to reveal answer
Answer
bin/magento theme:list
Revision Notes
Key Takeaways
- 1. Themes live in app/design/frontend/Vendor/ThemeName/
- 2. theme.xml defines title, parent theme, and media preview
- 3. registration.php registers theme with ComponentRegistrar
- 4. Fallback chain: Custom → Parent → Blank → Core
- 5. Run setup:upgrade after creating themes
Interview Tips
- • Explain the fallback mechanism and file resolution
- • Know the theme directory structure
- • Discuss when to use parent themes vs standalone themes
- • Be ready to create a basic theme from scratch
Cheat Sheet
Theme location: app/design/frontend/Vendor/Theme/
theme.xml:
<title>Theme Name</title>
<parent>Magento/luma</parent>
registration.php:
ComponentRegistrar::register(THEME, 'frontend/Vendor/Theme', __DIR__)
Fallback: Custom → Parent → Blank → Core