Yes, the last post on the forum was made 2 days ago. I just created a new post and vuala - it works and also the template is brand new. Looks like the the post statistics somehow was reset after upgrade, this is why it didn't pick up the topics created earlier this week. Thanks for explanation!
Having trouble with template calls
-
So, I'm trying to add some settings into the admin panel for a plugin I'm trying to make. But right away, I'm having trouble figuring out how to get a page to come up in the admin panel for the settings.
I looked at the dbsearch plugin among some others to try and figure out how, since I couldn't find much in the docs.
So from there, in my library.js I have this:
Author.addAdminLink = function(custom_header, callback) { custom_header.plugins.push({ "route": "/plugins/json-auth", "icon": "fa-book", "name": "JSON Auth" }); callback(null, custom_header); };
The "JSON Auth" button comes up fine in the admin panel, but when I click it I get
/api/admin/plugins/json-auth Not Found
I set up the directory structure to match how dbsearch's is, with
nodebb-plugin-json-auth/templates/admin/plugins/json-auth.tpl<h1>JSON Auth</h1> <hr /> <form> <p> Auth Settings </p> <div class="alert alert-info"> <p> <label>Client ID <br /><small>Unique ID for the site</small></label> <input type="text" data-field="json-auth:id" title="Client ID" class="form-control" placeholder="randomness123"> <label>Secret Key <br /><small>Secures the authentication. Do not give it out to anyone.</small></label> <input type="text" data-field="json-auth:secret-key" title="Secret Key" class="form-control"> <label>Site Name <br /><small>Displayed on buttons to users</small></label> <input type="text" data-field="json-auth:name" title="Site Name" class="form-control" placeholder="My Site"> <br /> <label>Auth URL <br /><small>URL that will be called that should supply the user information as JSON</small></label> <input type="text" data-field="json-auth:auth-url" title="Auth URL" class="form-control" placeholder="http://path.to/auth"> <label>Login URL <br /><small>URL where someone logs in if they aren't already.</small></label> <input type="text" data-field="json-auth:login-url" title="Login URL" class="form-control" placeholder="http://path.to/login"> <label>Registration URL <br /><small>URL for new user registration</small></label> <input type="text" data-field="json-auth:registration-url" title="Registration URL" class="form-control" placeholder="http://path.to/register"> <br /> </p> </div> </form> <button class="btn btn-primary" id="save">Save</button>
And in plugin.json I've included
"staticDirs": { "templates": "./public/templates", "json-auth": "public" }, "templates": "./public/templates"
I'm not sure what I'm missing here.
-
Check out nodebb-plugin-kitchen-sink adminPage.
Basically, you need to create two routes, you can add them in your appLoad hook like so:
Author.init = function (params, callback) { function renderAdmin(req, res, next) { res.render('admin/plugins/json-auth', {}); } params.app.get('/admin/plugins/json-auth', params.middleware.admin.buildHeader, renderAdmin); params.app.get('/api/admin/plugins/json-auth'', renderAdmin); callback(); }
The kitchen sink has explanations of what all this does.
-
Ah yes. I see that now. Thanks!
-
I must still be missing something, since I'm still getting the
/api/admin/plugins/json-auth Not Found
Maybe I'm missing something with the path itself. Let me copy more of it, so maybe it'll become clear
Author.addAdminLink = function(custom_header, callback) { console.log('admin link call from json-auth...'); //logs fine custom_header.plugins.push({ "route": "/plugins/json-auth", "icon": "fa-book", "name": "JSON Auth" }); callback(null, custom_header); }; function renderAdmin(req, res, next) { console.log('render called', req, res); //this is not getting logged, so it must not get called! res.render('admin/plugins/json-auth', {}); } Author.init = function(params, callback) { console.log(' --- init hook called'); //logs fine params.app.get('/admin/plugins/json-auth', params.middleware.admin.buildHeader, renderAdmin); params.app.get('/api/admin/plugins/json-auth', renderAdmin); callback(); };
It's my understanding that the "/api/admin/plugins/json-auth" error is from that page being requested. And "params.app.get('/api/admin/plugins/json-auth', renderAdmin);" should be called on its request, which should call that function to "res.render('admin/plugins/json-auth', {});". But that function isn't being called.
I can't see what I'm still missing, there. -
@Sadtaco Sorry, it looks like that plugin may be a little outdated. You actually have to call params.router now.
params.router.get('/admin/plugins/json-auth', params.middleware.admin.buildHeader, renderAdmin); params.router.get('/api/admin/plugins/json-auth', renderAdmin);
-
That was it.
Ah, I should have noticed that, looking at some other plugins. Thanks.