0

How can add CSS and JS File in admin panel of specific page.too many pages in admin panel e.g product,sales->order ,order view ,invoice,ship etc . . .

I want to load 1 CSS or JS file in New Invoice page.

Or other solution will be work for me if add CSS or JS code in .phtml file?

how can add this ?

Rakesh Donga
5,4442 gold badges26 silver badges58 bronze badges
asked Mar 20, 2019 at 12:26

1 Answer 1

1

1 Create a module for example Vendor/Module

2 Create a new file view/adminhtml/layout/default.xml in the module

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <head>
 <css src="Vendor_Module::css/test.css"/>
 <script src="Vendor_Module::js/test.js"/>
 </head>
</page>

3) Add .css file and add js file in web folder as below path:

view/adminhtml/web/css/test.css
view/adminhtml/web/js/test.js

Run below commands and check.

php bin/magento cache:clean

php bin/magento setup:static-content:deploy

answered Mar 20, 2019 at 12:47
2
  • Rakesh Donga ! it include both files. But jquery code is not run. require([ 'jquery', 'jquery/ui'], function($){ $(document).ready(function($) { console.log('asdf'); }); }); error in console is TypeError: require is not a function how can write code for jquery ? Commented Mar 20, 2019 at 14:26
  • 1
    @HaFizUmer check here : magento.stackexchange.com/a/266479/68695 Commented Mar 20, 2019 at 18:51

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.