3

I had created a couple of cms static blocks in Magento 2 luma theme and added inline styles and javascript inside the blocks. Now I'm confused that where I could place those CSS and js files inside the directory and how to call it.

Mohit Kumar Arora
  • 9,951
  • 7
  • 27
  • 55
ren
  • 365
  • 2
  • 15

1 Answers1

3

For styling your CMS Blocks add custom CSS, js or adding bootstrap, call files in default_head_blocks.xml

#app/design/frontend/yourvendor/yourtheme/Magento_Theme/layout/default_head_blocks.xml


<css src="css/bootstrap.css" />
<script src="js/bootstrap.js"></script>

Place both files under /app/design/frontend/yourvendor/yourtheme/web/css or js

you can call all required CSS and js files in same way

Mohit Kumar Arora
  • 9,951
  • 7
  • 27
  • 55
Manoj Deswal
  • 5,785
  • 25
  • 27
  • 50
  • I couldnt see any files inside app/design/frontend. – ren Jun 27 '17 at 07:11
  • you should have extended your theme – Manoj Deswal Jun 27 '17 at 07:18
  • I tried to add the custom css file inside vendor\magento\theme-frontend-luma\Magento_Theme\web\css ,And called css files inside vendor\magento\theme-frontend-luma\Magento_Theme\layout\default_head_blocks.xml.But css is not lodaing. – ren Jun 27 '17 at 09:29
  • I found that ,we had to paste the css files inside pub/static frontend/Magento/luma/css and this worked for me. – ren Jun 27 '17 at 09:48
  • Bad idea @ren - That directory will be deleted when you run a static-content deploy and you'll lose your changes. – Ben Crook Jun 27 '17 at 09:49
  • this will be gone once you clear the cache and deploy static content this is not the right place to add your custom css , you need to extend your theme – Manoj Deswal Jun 27 '17 at 09:51
  • yes u r right manoj.Can u tell me how to extend the magento luma theme. – ren Jun 29 '17 at 10:09
  • This is described in previous question : https://magento.stackexchange.com/questions/91930/how-to-extend-the-luma-theme – Manoj Deswal Jun 29 '17 at 10:21
  • According to magento front end developer guide icreated a new theme and configured it in backend.Now im confused about default_head_blocks.xml.I already pasted Magento_Theme folder from magento luma theme from vendor and passed css link in default_head_blocks.xml,unfortunately css file is not loding. – ren Jun 29 '17 at 12:11