1

Looking for some help here regarding adding styles and scripts(.css, and .js files) to a header on my page.

I know that i have to be on developer mode to do this but i don't know where i have to put my files, this is what i have done so far:

i have added it to my file tree here is the file paths....

/apps/magento/htdocs/app/design/frontend/Web/Css
/apps/magento/htdocs/app/design/frontend/Web/Js
/apps/magento/htdocs/app/design/frontend/Vendor/Theme/Magento_Theme/Layout

Am i doing anything wrong?

Please advise. Looking forward to your reply as i can't find it in my header of my page.

I have total 7 files 2 .css and 5 .js files and one default head blocks under layout (this is where i added in the src, and href to)

I think this is wrong?

Please keep in mind that i am using Magento2 via AWS Lightsail and Lightsail ssh, along with AWS cloud 9 for file tree(as path may be different) also please note that i created a new topic due to none existing with Lightsail path

Thank you.

inrsaurabh
  • 1,676
  • 2
  • 26
  • 54

1 Answers1

0

Magento 2 uses RequireJS to load .js files within your project. You can find the requirejs-config.js file in the root of your theme.

See following link for more: Add custom Javascript using RequireJs

Also, I advise you not to edit any core files. The cleanest approach would be creating your own theme, for example copying the Luma theme and editing it to your own likes.

The way of including .css within your project is right, you include this in your default_head_blocks.xml in Magento-Theme

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Condor
  • 637
  • 8
  • 31
  • thank you for your help Bramulous, i still have not figured it out. Also to Jai , ManojDeswal , ManashviBirla , Piyush , Priyank note this is not a duplicate as the CLI for magento via aws lightsail path is different please provide me the link to the duplicate with a adding .css and .js for magento via aws lightsail. – rav narayan Mar 28 '18 at 04:27
  • Could you be more specific about what you can't figure out? What is the first thing you are trying to accomplish? – Condor Mar 28 '18 at 06:01
  • hey @bramuious I am trying to add style sheet to my website i have 7 files in total 2 of them are .css, and the other 5 are .js files. so far i have attached them to my file tree as explained above in the question. now that it has been added (not sure in the correct place) i see it in my page and also i don't see it when i view page source – rav narayan Mar 28 '18 at 06:47
  • Are you using a custom theme? If yes, do you have a requirejs-config.js file in your root directory of the custom theme? – Condor Mar 28 '18 at 06:51
  • hey, no i am not using a custom theme... is that what i should do 1st? is so, how would i do that? thank you. – rav narayan Mar 28 '18 at 06:56
  • Yes, that would be a good start. That way it is way easier to customize the webshop to your needs. See the following link: https://magento.stackexchange.com/questions/112655/theming-for-magento-2-starting-from-scratch From there, you can include .js and .css in the way I told you how you can do it. I do not have experience with AWS sail but I presume this should be possible to do. – Condor Mar 28 '18 at 07:00
  • Thank you bramulous, I will follow the instruction on the link provided. Regards, – rav narayan Mar 29 '18 at 02:44