How to properly setup your admin templates to allow ajaxification to work?


  • Plugin & Theme Dev

    There really needs to be some kind of guide for this, because I can't figure it out without having to dig through the NodeBB source or go through extensive debugging. I only ever get it to work with cold loading, but never ajaxification. It shouldn't be so difficult to make something to simple work.

    What are the requirements for the template path? Admin page route?


  • Admin

    I have my imgur plugin setup like this

    upload-6ccbecde-89b6-455d-9be6-fbc52278e4f5

    Then the admin page is rendered with

    params.router.get('/admin/plugins/imgur', params.middleware.applyCSRF, params.middleware.admin.buildHeader, renderAdmin);
    params.router.get('/api/admin/plugins/imgur', params.middleware.applyCSRF, renderAdmin);
    
    function renderAdmin(req, res, next) {
    	res.render('admin/plugins/imgur', someData);
    }
    

    So the path in res.render and the routes in the router.get match the path templates/admin/plugins.

    Does that help?


  • Plugin & Theme Dev

    @baris I thought I had exactly that as well, but I'll double check tomorrow.

    Is it correct though that it will currently only work if you follow the admin/plugins/* pattern? I think I noticed that about a month or so ago.


  • Admin

    I'm not sure if you have to follow the admin/plugins structure but the above setup works for me in ajaxify so that's what I stick to.

    I think the first part might be mandatory ie public/templates the rest you can change as long as you match it with the res.render and router.get calls.

    @psychobunny might have a definitive answer.


  • Plugin & Theme Dev

    @baris public/templates should be the last thing that matters, since you can define the templates folder in your plugin.json.

    Edit: got it working somehow. I vaguely remember being forced to adept to the admin/plugins/* structure though, so I'd still like to know if this is still the case.


Log in to reply
 


Star

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