Jump to content

Admin Custom Files


Martijn Geerts

Recommended Posts

Why not just add the file via hook? https://processwire.com/talk/topic/20725-add-possibility-to-prepend-or-append-scripts-and-stylesheets-in-admin/?do=findComment&comment=211800

$wire->addHookBefore('AdminTheme::getExtraMarkup', function (HookEvent $event) {
  $config = $this->wire->config;
  $url = $config->urls("MyModule");
  $config->scripts->add($url."tabulator/js/tabulator.min.js");
  $config->styles->add($url."tabulator/css/tabulator.min.css");
});

 

  • Like 2
Link to comment
Share on other sites

@adrian I'd ask you to rethink recommending AOS for such simple tasks as adding scripts to the admin. I know you are a big fan of it, but the only reason I see for using AOS or ACF is if you don't know how to place a hook to your system. But if you are able to do that, it is a lot better to copy a 4line hook than adding another dependency to your site.

The hook will likely work without any problems for several years... AOS is already unmaintained and has introduced problems to several of my sites that where quite hard to find...

It would be even better of course to put that hook into a dedicated simple module that does everything that the injected script is for ? 

  • Like 2
Link to comment
Share on other sites

@bernhard - I completely agree that there is no point using AOS for just this purpose. That was my intention by saying "if you are already running" in my comment above. 

I know it's unmaintained, but with the features I use from it, I haven't noticed any bugs - I am sure there are likely some features that are buggy. The problem is that I really struggle to use PW without it.

Just an FYI - when it was first being developed, I thought it was a crazy idea - way too hard to maintain and make stable with all those features, but it works for my needs, but I completely agree it's not something that should be recommended for one simple feature like this.

  • Like 3
Link to comment
Share on other sites

On 4/19/2021 at 7:03 PM, Martijn Geerts said:

I really wanted to work in the outside air and with my hands again. I'm building garden sheds these days and I love it.

? sounds good! ? All the best for you! ???

  • Like 1
Link to comment
Share on other sites

On 4/18/2021 at 5:39 PM, Macrura said:

the root relative url is presumably "/processwire_test1/site/templates/libraries/path-to-some-file.js" but the module outputs this:

processwire_test1/processwire_test1/site/templates/libraries/path-to-some-file.js

FWIW, I came across a similar problem with my DbMigrate module. In my case, it happened if the admin root was not just /processwire/. My solution was to use $pages->get(2) rather than $urls->admin for the admin root. This may be completely irrelevant in your case, of course ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...