How to insert own js-files to adjust theme of nextcloud?

I am trying to adjust the theme of the cloud according to our company design. I was able to alter the CSS and now I want to slighty adjust the HTML using Javascript. I tried to insert js-files into the themes directory according to the documentation of nextcloud: themes => ‘themename’ => core => js => script.js ( but this doesn’t work. The script-file isn’t loaded. I couldn’t find anything on the web or in this forum.
Can anyone help and tell me where I can put my own Javascript and what I have to do to let the site use this script-file?


@enoch85 @juliushaertl @jan ^ maybe one of you can help with this

Hey @Peggy_K – you probably read it already but just as info again: we advise against theming the JS or templates as they will very likely need to be adjusted on every update.

Anyhow it should be possible to replace a file. CSS and images can simply be added, but JS and PHP need to be overwritten, that is you should add it to an existing file. cc @bjoern & @MorrisJobke who can help more in this regard with theming and JS. :slight_smile:

(@Peggy_K and by the way, if you want to get involved with the actual development of Nextcloud, you are very welcome at :slight_smile: Javascript/frontend contributors are always appreciated.)

Thank you for the feedback.:slight_smile: I hoped there would be a way around this as we update quite frequently. Thank you anyway.

(Oh, thank you, maybe I give it a try)

Has there been any solution to this problem? I am desperate for documentation that details how to add custom JS.

I’ve found this:

but that document provides no contextual examples of implementation. Right now the system is not reading when I place the script('myapp', 'script'); command in the layout.user.php file, and I can’t figure out how to attach a custom template that will be recognized in my theme, so I’ve been using the jquery.ui.fixes.js file to run all of my custom JS because I know it loads on the pages. However, it is far up in the stack so I have lots of problems with js being overridden. Now I’m hearing that that particular file is thinking of being deprecated. PLEASE help!!! This is so so so so frustrating.

Maybe this helps?

This application allows the admin to include JavaScript into all Nextcloud pages for web analytics for example.

I figured out a way to make this work… you need to link your JS file in the following way in your template file.

<script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="/path/to/script.js"></script>

1 Like

wait a minute… where am I supposed to add this code? In which file?

Thanks so much for this! Worked for me too. Only had to add defer attribute for script to execute after page load. Kudos!

Try including the scripts directly on core/templates/layout-user.php