3

I have a custom theme that has no parent specified in the theme.xml.

But it still loads the styles-l.css and styles-m.css specified in the blank theme. (specified in: /vendor/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks.xml)

So it looks like it falls back on the blank theme. When i change the xml file in the blank theme the changes also appear in my custom theme.

The CSS files themself are not loaded from the blank theme.

So how does this fallback actually work? Does it always fallback to the base theme for layout updates or something? Even when no parent is entered in the theme.xml.

4

The problem was my theme had a parent before but it was removed later.

Flushing cache and removing the static and generation files did not work.

In the theme table of the database the parent was still set to id 1 which is magento/blank. Set the field to NULL and all started working as expected.

  • Hi Jeffrey, I have the reverse issue...that is when I made a custom theme in 2.0 stable version at that time I did not setup <parent> tag in theme.xml so in theme table in parent_id column it was NULL but then when I set <parent> tag & refresh...that parent theme did not come in effect & in theme table in parent_id column it is not setting to 1...don't understand what to do...how to do? You have any idea? I cleared the cache...even hit bin/magento setup:di:compile command also but nothing happened. – KA9 Dec 31 '15 at 12:18
  • Did you clear the static files? I assume that's the issue. – Jeffrey Jan 4 '16 at 11:33
  • Yes Jeffrey, me cleared the static files also...like going into pub/static & deleted everything except .htaccess but until & unless I manually set 1 in that theme table.....it is not taking parent theme at all & so if I remove web folder from my theme....all css & images are going off...once I set 1 in that table...it gets css & images from parent theme & all look nice :) Umm, well Jeffrey...do I need to hit upgrade command? like in case of module creation we do - bin/magento setup:upgrade – KA9 Jan 4 '16 at 12:05
  • You're problem is fixed now? Atleast that's what you comment looks like. I don;t think you need to do the upgrade command. But I am also just starting with Magento 2. – Jeffrey Jan 4 '16 at 12:33
  • Yes the problem is solved by putting 1 in theme table's parent_id column in my theme's row but it shouldn't be like this....I should not manually set 1......by clearing cache or doing something else...it should be done automatically :) haha Ok Jeffrey no worries as we all have just started learning magento 2....If I find something, will definitely post here :) Thanks again for your help :) – KA9 Jan 4 '16 at 13:28
1

the parent theme overwrites base theme of module (files contain in app/code), the child theme overwrites the parent
file process order follow alphabetical
If layout file belongs to different module, the order to run will be: independent module, dependent module
your custom theme can inherit from the Magento Blank theme

  • Well the issue is that i don't want a parent theme. So i did not assign a parent in my theme.xml. It doesn't load the contents of the css file from the blank theme but it does load the xml from the blank theme. So this is not what i expect. – Jeffrey Dec 24 '15 at 7:29
  • what happens if parent tag is not specified? – jafar pinjar Dec 24 '18 at 10:30
  • If you have parent fall back magento will check in parent theme if file assets not available when it requested. Otherwise if you not specific magento will check in your theme only. If it not found. Errors will raise – mrtuvn Dec 25 '18 at 9:53
1

Themes in Magento 2.x is located in : \app\design\Area\Namespace\ThemeName

It will contain mainly:

registration.php : For registration of theme.

<?php

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

composer.json :

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

theme.xml : For deceleration of theme

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

Here this is child theme of Blank.

Layout files will be placed under this theme to make theme specific pages.

If theme does not have layout files it will take the layout files of it's parent theme.

And in case the parent theme also does not have the layout file it will load layout file defined in the module in view\Area\layout

In Magento 1.x pattern of theme fallback is :

Current package / Current Theme > Current Package / Default theme > Base Package / Default theme.

In Magento 2 pattern of theme fallback is :

Layout defined in current theme > Layout defined in parent theme > Layout defined in module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.