[QUESTION] Plugin ACP templates relative URLs
-
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
-
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 inRELATIVE_PATH
.Also, no need to pass in
csrf
either -
got it thanks!
Copyright © 2024 NodeBB | Contributors