[QUESTION] Plugin ACP templates relative URLs


  • Plugin & Theme Dev

    @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

    nodebb-plugin-something
         index.js
         plugin.json
         package.json
         public
             js
                 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"
             css
                 acp.something.css // <-- same as acp.something.js
             templates
                 admin
                     plugins
                         something.tpl   
    

    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


  • Admin

    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);
      callback();
    }
    

    ... 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 😄


  • Plugin & Theme Dev

    got it thanks!


  • Plugin & Theme Dev

    @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


  • Admin

    @bentael yes, I believe that is the case.




Looks like your connection to NodeBB was lost, please wait while we try to reconnect.