This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have some custom JavaScript running in the backend (globally) so it appears on all backend pages. Currently, I have a custom plugin with the code it needs inside the boot method. Something like:
Event::listen('backend.page.beforeDisplay', function ($backendController, $action, $params) {
$backendController->addJs('/plugins/acme/assets/custom.js');
});
I'm thinking it would be nice to get rid of this plugin entirely coz it pretty much does this and nothing else. I found that there is a Customize Back-end section with Styles tab (/backend/branding#primarytab-backendlangbrandingstyles) which works well for CSS but no equivalent "Script" tab for Js. Is there an alternative?
Last updated
It's an interesting idea, although, allowing custom JS here, or even custom injection to the layout could open up some security concerns from a platform perspective. Whereas stylesheets are generally considered safe
A couple of options, you could build a more generic plugin that extends this form and adds "Custom JavaScript" to the form, in addition to the stylesheets. This would give the desired functionality but would need to be supplied with a warning about the security implications.
Or you could add this code to your bootstrap/app.php
file...
/*
|--------------------------------------------------------------------------
| Inject to backend head
|--------------------------------------------------------------------------
*/
$app->before(function() {
Event::listen('backend.layout.extendHead', function($controller, $layout) {
return '<script> alert("hello"); </script>';
});
});
As a side note, we understand this need for simple modifications like this without plugins and will look at improving the support in a future release.
Hope this helps!
1-3 of 3