[QUESTION] Plugin ACP templates relative URLs

NodeBB Development
  • @3rd-Party-Developers @julian

    I think every plugin I looked at so far uses inline js/css on the ACP template, I want to be able to include a js and css files instead.

    Say I have this plugin

                 acp.something.js // <-- I want this to be accessible only on in the ACP page of the plugin, no need to compile it into nodebb.min.js, I don't want to use "filter:scripts.get"
                 acp.something.css // <-- same as acp.something.js

    in something.tpl

    <link href="{RELATIVE_PATH}css/acp.something.css" rel="stylesheet" >
    <script src="{RELATIVE_PATH}js/acp.something.js"></script>

    this only works if RELATIVE_PATH === "", but what about folder installs ?

    <script src="/plugins/nodebb-plugin-something/js/acp.something.js"></script>

    somewhere in index.js

            res.render('admin/plugins/something', {RELATIVE_PATH: nconf.get('relative_path') /* do i have to do this, or is this var global to the templates somehow? */, csrf: req.csrfToken()});

    ^ question in comment

  • Because you control where the admin page is mounted:

    myPlugin.init = function(data, callback) {
      data.router.get('/admin/plugins/myPlugin', data.middleware.admin.buildHeader, render);
      data.router.get('/api/admin/plugins/myPlugin', render);

    ... you can expect that ../../ gets you back to the public root, so no need to pass in RELATIVE_PATH.

    Also, no need to pass in csrf either 😄

  • got it thanks!

  • @julian said:

    no need to pass in csrf either

    that's in 0.6 right?
    but any version that supports 0.5.x, I had to pass csrf

  • @bentael yes, I believe that is the case.

Suggested Topics

  • 0 Votes
    2 Posts

    nodebb-plugin-write-api is one

  • plugin load sequence

    NodeBB Development
    0 Votes
    23 Posts

    I'm fine with it being each. But that's really a separate issue. The app.load hook is not where we should be modifying templates.

  • 0 Votes
    2 Posts

    I have solved it. use "static:app.load" hook , and use the method's first arguments ,we can setting routes to do what we want to do

  • 2 Votes
    13 Posts

    Hi @julian , while restarting the forum (1.19.1) , I get this "warning" for canned-responses plugin... Is this a problem or normal?

     started 2022-02-03T04:28:25.721Z [4567/3637012] - info: [build] Building in series mode 2022-02-03T04:28:25.724Z [4567/3637012] - info: [build] plugin static dirs build started 2022-02-03T04:28:25.756Z [4567/3637012] - info: [build] plugin static dirs build completed in 0.032sec 2022-02-03T04:28:25.756Z [4567/3637012] - info: [build] requirejs modules build started 2022-02-03T04:28:35.741Z [4567/3637012] - info: [build] requirejs modules build completed in 9.984sec 2022-02-03T04:28:35.743Z [4567/3637012] - info: [build] client js bundle build started 2022-02-03T04:28:39.189Z [4567/3637012] - info: [build] client js bundle build completed in 3.446sec 2022-02-03T04:28:39.189Z [4567/3637012] - info: [build] admin js bundle build started 2022-02-03T04:28:43.542Z [4567/3637012] - info: [build] admin js bundle build completed in 4.353sec 2022-02-03T04:28:43.543Z [4567/3637012] - info: [build] client side styles build started 2022-02-03T04:28:51.795Z [4567/3637012] - info: [build] client side styles build completed in 8.252sec 2022-02-03T04:28:51.796Z [4567/3637012] - info: [build] admin control panel styles build started 2022-02-03T04:28:58.818Z [4567/3637012] - info: [build] admin control panel styles build completed in 7.022sec 2022-02-03T04:28:58.820Z [4567/3637012] - info: [build] templates build started [benchpress] warning: output bloat due to ambiguous inner BEGIN --> admin/plugins/canned-responses.tpl:44:17 | 44 | <!-- BEGIN responses --> | ^^^^^^^^^ `responses` could refer to the top-level value `responses` or the `.responses` property of the current element, so compiler must emit code for both cases | note: Migrate to modern syntax to avoid the ambiguity. This will become an error in the future. 2022-02-03T04:29:00.904Z [4567/3637012] - info: [build] templates build completed in 2.084sec 2022-02-03T04:29:00.905Z [4567/3637012] - info: [build] languages build started 2022-02-03T04:29:07.261Z [4567/3637012] - info: [build] languages build completed in 6.356sec 2022-02-03T04:29:07.264Z [4567/3637012] - info: [build] Asset compilation successful. Completed in 41.54sec. [cluster] Restarting... 2022-02-03T04:29:07.321Z [4567/3637012] - info: [app] Shutdown (SIGTERM/SIGINT) Initialised. 2022-02-03T04:29:07.332Z [4567/3637012] - info: [app] Web server closed to connections. 2022-02-03T04:29:07.338Z [4567/3637012] - info: [app] Live analytics saved. Clustering enabled: Spinning up 1 process(es). 2022-02-03T04:29:07.393Z [4567/3637012] - info: [app] Database connection closed. 2022-02-03T04:29:07.394Z [4567/3637012] - info: [app] Shutdown complete. [cluster] Child Process (3637012) has exited (code: 0, signal: null) 2022-02-03T04:29:08.058Z [4567/3646564] - info: Initializing NodeBB v1.19.1
  • 0 Votes
    27 Posts

    @Alex said:

    I will edit the plugins locally then until the plugins's authors put the modification. Thank you @julian for this quick fix. @a_5mith could you let us know when you have pushed it to npm or github please? 😉

    Yeah sure.