Magento – Magento 2 theme giving error Unable to load theme by specified key: ‘Yogesh/thetheme’

magento2theme

I have try to create custom theme I have got following error.

Unable to load theme by specified key: 'Yogesh/mytheme'

Below is my folder structure.

\magento2\app\design\frontend\Yogesh\mytheme

  • media
    • preview.jpg
  • composer.json
  • registration.php
  • theme.xml

Following are content of files.

Composer.json

{
    "name": "magento/theme-frontend-blank",
    "description": "N/A",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/theme-frontend-blank": "100.0.*",
        "magento/framework": "100.0.*"
    },
    "type": "magento2-theme",
    "version": "100.0.1",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ]
    }
}

registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Yogesh/mytheme',
__DIR__
);

theme.xml

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

I have try with php bin/magento setup:upgrade but my module is not registered, not showing in config.php.

After I have try to setup:static-content:deploy but my theme content not deployed.

My theme is not able to load what mistake I have doing?

Best Answer

  1. Try clear the cache and run the bin/magento setup:static-content:deploy again.
  2. To add new theme you need to turn in developer mode.
  3. Sometimes new theme added to theme table in our database with param type=1 (virtual theme). Try to set it to 0 (physical theme). For example:

mysql> insert into theme
(parent_id,theme_path,theme_title,preview_image,is_featured,area,type,code) VALUES ('1','MyVendor/Base','MyVendor Base', NULL, 0, 'frontend', 0, 'MyVendor/Base');

We can read more here:

https://github.com/magento/magento2/issues/3409 https://github.com/magento/magento2/issues/2797

Related Topic