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?
blocksmagento-2.0magento2
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?
Best Answer
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>
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
andjs
rather than CallCSS
andJS
files directly intolayout
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 underapp\code\<Vendor>\<ModuleName>\view\frontend\web\css\source
. So It will call automatically as well as_module.less
will compile bygrunt tool
and converted into your theme or module css