3

I have custom view.phtml. I Want add my.css and my.js in <head></head> 2 file in app\code\Test\New\view\frontend\web\css.

How do it?

7ochem
7,61516 gold badges54 silver badges82 bronze badges
asked Oct 15, 2015 at 8:13
1
  • was bellow answer useful ? Commented Jan 5, 2016 at 7:16

1 Answer 1

6

You can add CSS file as following way for your custom module.

Open you layout file e.g. modulename_index_view.xml and following code in <head>

<head> 
 <css src="Test_New::css/my.css"/>
</head>

to add custom module JS file you can use standard way as mentioned with below link.

How to load custom module js file in magento 2?

My suggestion (Optional)

You can use the standard way of Magento 2 to call css and js rather than Call CSS and JS files directly into layout file.

You can call JS using requirejs module. (You can maintain dependency of code.)

You may call css file using _module.less just put it under app\code\<Vendor>\<ModuleName>\view\frontend\web\css\source. So It will call automatically as well as _module.less will compile by grunt tool and converted into your theme or module css

answered Oct 15, 2015 at 9:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.