I am new to Magento 2 Theme Development; I have gone through the frontend development guide.
I set my child theme to Magento Blank theme. I have done all that the guide says and added my CSS file but it is not showing on the frontend.
I have cleared all the caches and deployed static content.
Below is my setup. Any help would be great!
Local theme path: design/frontend/Speedcrete/speedcrete
Inside the folder speedcrete the structure is:
|-etc
| |-view.xml
|
|- Magento_theme
| |-layout
| |-default_head_blocks.xml
|
|
|-media
| |-preview.jpg
|
|-web
| |-css
| |-custom.css
| |-fonts
| |-images
| |-js
|
|-registration.php
|-theme.xml
Here is the code for default default_head_blocks.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="Magento_Theme::css/speedcrete.css"/>
</head>
</page>
Here is the code for the theme.xml file:
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>speedcrete</title> <!-- your theme's name -->
<parent>Magento/blank</parent> <!-- the parent theme, in case your theme inherits from an existing theme -->
</theme>
Let me know if I need to supply more files.
I have tried to run the following commands and then clear the cache and no joy.
php bin/Magento setup:upgrade --keep-generated
php bin/Magento setup:static-content:deploy
Only another thing it might be is that there are no files under design/frontend/Magento/blank. I looked at another forum and they said it was ok as it is stored elsewhere. It seems to be the case as the "blank" theme is showing when I have my custom theme activated. Only cannot see any custom CSS I add.
3 Answers 3
In my case, i just add default.xml to my themes. and it's working fine.
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="default_head_blocks"/>
...
and default_head_blocks.xml
<head>
...
<css src="css/custom.css"/>
...
</head>
If you want your custom CSS in web/css folder directly within theme root then update your default head blocks to remove the Magento_Theme so that it isn't looking in the magento theme directory:
<head>
<!-- Add local resources -->
<css src="css/speedcrete.css"/>
</head>
I can't see your speedcrete.css in your tree depicted in question however this should go where custom.css is located.
Also the Blank theme being empty is fine depending on how you installed Magento, if it was installed with composer the theme will be located in vendor/magento/theme-frontend-blank/ directory. If downloaded from github i believe it should be design/frontend/Magento/blank however.
-
It was installed via composer, as the blank theme resides in vendor/magento/theme-frontend-blank.Scott Lunnon– Scott Lunnon2017年08月09日 13:48:08 +00:00Commented Aug 9, 2017 at 13:48
-
That hasn't seemed to have worked!Scott Lunnon– Scott Lunnon2017年08月09日 14:08:07 +00:00Commented Aug 9, 2017 at 14:08
-
So have you disabled cache / cleared cache? Also check markup and console to see if the file is showing or just not being found.harri– harri2017年08月09日 16:37:37 +00:00Commented Aug 9, 2017 at 16:37
-
Sorry yeah I see you mentioned clearing cache already. I would also take the keep generated out of your deploy commandharri– harri2017年08月09日 17:24:05 +00:00Commented Aug 9, 2017 at 17:24
-
I have re-run the --keep-generated out of my deploy command. The file isn't appearing in the console.Scott Lunnon– Scott Lunnon2017年08月10日 07:38:48 +00:00Commented Aug 10, 2017 at 7:38
One thing that people should try because it is an absolute keyboard banger if you have it as a bug, is check the casing of all files in your theme directory:
For instance for me changing <theme_root>/Magento_theme back to <theme_root>/Magento_Theme where I had accidentally changed the name.
For me the incorrect casing of the module override name meant that Magento simply ignored the directory when loading all resources on page refresh
<magento_root>/vendor/magento/theme-frontend-<name>