Adding custom javascript with custom theme in 10.3

For OC10.3, I’ve successfully created and am using a custom theme within the /apps folder. I can override CSS by using the /apps/my-theme/core/css/styles.css file to write my custom styles.

However, im having an issue figuring out how to add my own custom javascript, that doesnt override any existing core/marketplace apps javascripts, but rather run the custom scripts in addition to existing js files.

Does anyone know how to accomplish this? Is there a specific file name i need to name my js file such that it can be included on all pages (user/public)?

Thanks for all that you do here.

You can include a script via your defaults.php file.

Please add the following:

	public function __construct() {
		// JS file
		\OCP\Util::addScript('your-theme', 'scriptname');


	public static function getThemePath() {
		return __DIR__;

Your JS file has to be in a folder called js in the root folder of your theme. Please note that the scriptname in the upper part is only the filename (without file extension).

1 Like

Thank you! This works perfectly. This should be documented.