I am very new to Magento 2.1.0. but want to install HTML theme (theme integration). When I deploy static content and also in pub folder I can see my .css file under css/source folder.
My theme Structure: <VendorName>/<themeName>/web/css/source.
and after that include my CSS and JS files into the Magento_Theme/layout/default_head_blocks.xml file. Below is my code:
**default_head_blocks.xml**
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<css src="css/source/bootstrap.min.css" />
<css src="css/source/font-awesome.min.css"/>
<css src="css/source/slick.css"/>
<css src="css/source/style.css"/>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/scripts.js"></script>
<script src="js/slick.min.js"></script>
</head>
</page>
I flush the cache, deploy the static content but when I see view source in the browser I am not able to my CSS and js file.
So can anyone help me?
Magento ver:2.1.0
Any kind of help will appreciative.
-
have you select your theme from admin?Nikunj Vadariya– Nikunj Vadariya2018年05月25日 09:52:01 +00:00Commented May 25, 2018 at 9:52
-
Check my answer will help you.Nikunj Vadariya– Nikunj Vadariya2018年05月25日 09:58:29 +00:00Commented May 25, 2018 at 9:58
-
In Magento 2, you can not see your CSS and JS in view source, for that you need to check in browser network and console tab (f12) because all these files running in the background. Better to add some CSS property and check in the frontend. Don't forget to flush the cache and to run static-content command.Nits– Nits2018年05月25日 10:06:58 +00:00Commented May 25, 2018 at 10:06
3 Answers 3
To apply a theme:
In Admin, go to CONTENT > Design > Configuration.
A Design Configuration page opens. It contains a grid with the available configuration scopes.
For example:
You need to refresh your cache (clear cache)
php bin/magento cache:flush
php bin/magento setup:static-content:deploy
For more information check Magento official document.
-
yes I set the theme from the adminHarshil Parekh– Harshil Parekh2018年05月25日 10:26:11 +00:00Commented May 25, 2018 at 10:26
Put your custom css in below path
/app/design/frontend/VendorName/themeName/web/css/font-awesome.min.css
And call in Magento_Theme/layout/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>
<css src="css/font-awesome.min.css"/>
</head>
</page>
You need to run below command
php bin/magento set:up
-
I used your code but I can't see any updates for css and js file.Harshil Parekh– Harshil Parekh2018年05月25日 13:09:10 +00:00Commented May 25, 2018 at 13:09
-
In which XML have you put above code, please share with me full path with actual XML nameHitesh Koshti– Hitesh Koshti2018年05月25日 13:51:09 +00:00Commented May 25, 2018 at 13:51
-
app/design/frontend/Mcardles/default/Magento_Theme/layout/default_head_blocks.xml file.Harshil Parekh– Harshil Parekh2018年05月26日 04:32:11 +00:00Commented May 26, 2018 at 4:32
-
Please check once in page view source. Your CSS was showing or not. If this project live please share with me URLHitesh Koshti– Hitesh Koshti2018年05月26日 07:47:20 +00:00Commented May 26, 2018 at 7:47
kindly run below commands
php bin/magento s:s:d -f
php bin/magento c:f