Magento 2 CE – Product View Does Not Inherit Default Head Block XML

frontendmagento-communitymagento2

First off let me just say, I am green when it comes to Magento (all versions) and have been trying to figure this out for two days and I am not sure what else to try. I have been fiddling with a custom template that inherits the Luma theme and I have figured out how to muddle through the xml files for block placements and so forth, mostly getting things to work by trial and error. I changed the default_head_blocks.xml located in my custom theme here:

/app/design/frontend/myvendor/mytheme/Magento_Theme/layout/default_head_blocks.xml

to include a custom css file to override some of the Luma css (mine is labelled as css/mycss.css):

<head>
    <meta name="x_ua_compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <css src="mage/calendar.css"/>
    <css src="css/mycss.css"/><!-- <<<--- I added this -->
    <script src="requirejs/require.js"/>
</head>

I was very happy with myself that something I did actually worked, until I went to look at the single product view (the category view inherits the css just fine and I also have the category set to apply my template to in-category products…something else I tried, not sure if that is right or not). I checked to make sure the product itself was also using my template under the Design tab in the admin area, which it says it is. Then I went to the catalog folder to try and mess around with all of the xml documents pertaining to product such as the catalog_product_view.xml, catalog_product_view_type_simple.xml, etc… and adding:

<head>
    <css src="css/mycss.css"/>
</head>

I should mention I did move all combinations of these xml files into both:

/app/design/frontend/myvendor/mytheme/Magento_Catalog/layout/

and/or

/app/design/frontend/myvendor/mytheme/Magento_Theme/layout/

Last thing to mention, I flush my cache every time I change something.

Anyway, I have Googled the crap out of this and I tried to adapt some Magento 1.x answers to try and solve it, but I can not figure it out with my limited Magento knowledge. Any push in the right direction would be helpful at this point because I am just staring at my Magento project folder right now with a dumb perplexed look on my face…


EDIT

After more "trial and error" I have deduced that this page, including the account signup, login, etc. are just using the base template…how do I know? I did the unthinkable! Just to test, I added my <css src="css/mycss.css"/> to the base theme's default_head_blocks.xml file located here:

/vendors/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks.xml

So I guess my question is, how come it's using the base template (which I already suspected it was doing) and not the one I am assigning it? I am missing something, but I don't know what it is or where to fix it.

Best Answer

For adding custom or as you say "mycss.css" in your theme layout
you have to place "mycss.less" file in to
app\design\frontend\Zenon\zenon\Magento_Theme\web\css\mycss.less
after that change the css debugging mode to public or client side.

after than do static content deploy using compressor

Related Topic