magento2: Extending Layout .xml files not working in child theme in different as to parent theme: Magento 2.0.4.
Root cause description
Steps to reproduce
- Add a theme to
app/design/frontendfolder (i.e. clone https://github.com/sivaschenko/magento2-sample-theme toapp/design/frontend/Sivaschenko/default/) - Login to Admin panel (or just reload the admin panel page)
select * from themeto ensure theme is added to the database (typeis0as it is a physical theme)- Remove the theme files/folder
- Reload the admin panel page
select * from theme(typefor the theme is now changed to1- virtual theme)- Return the theme files back
- Reload the admin panel page
select * from theme
Actual Result
type for the theme is still 1 - virtual theme
Expected Result
type for the theme should be 0 - it’s a physical theme
Issue description
Summary (*)
- Install Magento 2.0.4 on WAMP server 3.0 , Windows 10 Pro - 32bit, PHP 5.6.15, MySQL 5.7.9
- Created a child theme themeparent of Magento_blank in app\design\frontend*Vendor1*\themeparent with several layout xml files for extending, along with template .phtml files. Activated from admin. Working Fine.
theme.xml =>
<parent>Magento/blank</parent> - Created another child theme themechild of above theme themeparent (which is itself the child of magento blank). This childtheme is created in different vendor folder, i.e. Vendor2
This theme path is app\design\frontend*Vendor2*\themechild . Created layout .xml file inside to extend its parent theme layout. Activated this second level child theme from admin. The .xml files not even processed. Not working.
theme.xml =>
<parent>Vendor1/themeparent</parent>
3b. Although template .phtml files or .css files existing in childtheme are working fine if corresponding layout containers/blocks called in from the Vendor1\themeparent layout files.
- If for a test, the same child theme childtheme put inside same vendor of its parent i.e. Vendor1 , the theme path becomes app\design\frontend*Vendor1*\themechild and then the same layout .xml files works fine.
Already tried with clearing public/static and var folders. Also, tried after running with cli commands php bin/magento setup:static-content:deploy php bin/magento indexer:reindex php bin/magento setup:upgrade
But nothing solved it.
Examples (*)
The required theme inheritance is in this way: Magento_blank => Vendor1_themeparent => Vendor2_childtheme . (note vendor differ) Layout .xml fail to load in childtheme.
But if for a test, inheritance made this way: Magento_blank => Vendor1_themeparent => Vendor1_childtheme . (note vendor same) Layout .xml load properly and work fine in childtheme.
As per Magento 2 guidelines on http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-inherit.html#set-a-parent-theme it is clearly mentioned that “A parent and a child theme can belong to different vendors. For example, your custom theme can inherit from the Magento Blank theme.” . So, if I am creating a second level child theme (in vendor 2) from a parent theme (in vendor 1) which is a child of Magento_blank (vendor: Magento), this should ideally work fine. But its not happening. None of the layout .xml files processed to output if they are under different vendors. If I put both themes in same vendor, they are working fine.
Actual result
Extending layout .xml files in the 2nd level child theme in different vendor folder is not working.
Proposed solution
Why Magento 2.0.4 not working properly for 2 level theme inheritance with different vendor names? This is a serious issue, as if you suppose purchased a paid theme from somewhere (which they have created by inheriting Magento_blank), and now you want to create your child theme of that paid theme but in different vendorname folder (obviously under your companyname), you will not able to do so! You have only two choices left, either make your child theme inside their vendor name; or edit their theme .xml files to call your child theme template files or .css/.js (if in ur vendorname); the second case will obviously loose updates, weird way and not recommended.
Then what is the solution??
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 3
- Comments: 27 (6 by maintainers)
Commits related to this issue
- Merge pull request #4330 from magento-obsessive-owls/MC-16599 [Owls] MC-16599 Use Escaper methods — committed to magento/magento2 by davemacaulay 5 years ago
Hi, Thank you very much for giving me the sample code. I have checked it on same installation and it worked! I was amazed, matched the way to what I have done in my themes; your and my way both exactly same. Again activated my childtheme, and surprisingly it not worked. More surprised and fedup. 😦
Then I digged into the magento database, and I found out one amazing thing. In the ‘theme’ mysql table of magento database, somehow the ‘type’ column corresponding to my childtheme had value set as ‘1’ and all others were set ‘0’. Under suspicion, I tried to find what it means by comment in table column name which shows…
I guessed it may be a reason, and manually set the ‘type’ column value to 0 corresponding to my childtheme. Cleared var and public/static folders. Re-tested, and voila! it worked!!
This small issue has wasted my 4-5 days, with no solution. Even deactivation-activation or switching themes from admin was not resetting its value to 0 (it always remained 1) and so it never worked.
For a cross check to confirm, I deleted that row from database theme table, and reinstalled the theme, ran
php bin/magento setup:upgrade, and now its setting the value to 0, which is perfect and working automatically.Don’t know how it was set to 1 and when.
Anyways, the issue is solved now, and
, which can waste every developers time if not known. But, surprisingly this silly point is no where mentioned on the internet and not even on the magento documentation, which must be there. Hope this explanation and solution will help more people later who are getting frustrated with the same issue. 😃
Thanks.
I guess I found what was the problem.
If you have your theme fresh installed e.g.
https://github.com/magento/magento2/blob/6ea7d2d85cded3fa0fbcf4e7aa0dcd4edbf568a6/app/code/Magento/Theme/Model/Theme/Registration.php
The problem is that if theme is set as Virtual, for example you temporary removed theme directory from app/design/frontend, it’s cannot be set again as Physical and you can see it in described class code
So if you removed theme files from app/design/frontend and returned it there after some operations, or if you did some stuff that could re-register your theme - check the type field in the database.
By myself, I’d say that this is very unsafe to set those type of field, which could affect frontend rendering according to file operations done by site developers and not documenting it, nor giving any recommendations or warnings that theme is set to Virtual. I mean, really? This field exist in database and can cause serious problems, without any documenting or warnings.
@shoshweb ‘type’ is column name, table name is => ‘theme’, already mentioned. Reading plain english doesn’t need advanced user.
I wasted only 2 days! -> set 1 to 0 -> everything works fine! There should be a hint in the official magento docs. Or is there a hidden switch where you can set this value in the magento backend?
@shoshweb I’ll help you out. Go into phpMyAdmin. Click on the name of your database. You should see a search bar. Search for theme. Sometimes you have to click on the results to see the results. Click on the one that has _theme in the name. Click on that file. Once the table is loaded, look at the “type” column. That’s the column you want to edit. There should be an edit button or link at the beginning of the row. Click that and you will be able to edit that column. Hope this clarifies what you need to know.
I’m always quite put off about writing on here, It’s like a rule to be rude first and ruder later. Odd.