How can you add a JS (file) that runs in the admin environment?
This question relates too: Conditional field - Creating a ‘Flexible Content Field’ (like ‘Advanced Custom Fields’ wordpress plugin)
last edited 08/28/18 by Kenneth Joris
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
How can you add a JS (file) that runs in the admin environment?
This question relates too: Conditional field - Creating a ‘Flexible Content Field’ (like ‘Advanced Custom Fields’ wordpress plugin)
I don't know if its the correct hook. But this code seems to work.
This code goes into your themeName.php file,
located at user/themes/themeName/themeName.php
<?php
namespace Grav\Theme;
use Grav\Common\Theme;
class Base extends Theme
{
// Add assets to the Admin
public function onAssetsInitialized() {
if ($this->isAdmin()) {
// add JS
$this->grav['assets']->addJs('theme://js/admin.js');
}
}
}
Log in to reply.
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 2 | 57 | 14 hours ago | ||
| 2 | 65 | 17 hours ago | ||
| 1 | 33 | 18 hours ago | ||
| 2 | 68 | 5 days ago | ||
| 2 | 60 | 6 days ago |