How to call an API call from NodeBB theme?
-
@dev-wilco from server or from client?
-
@dev-wilco You could use ur own plugin and simply make an API call within the clientside javascript file of your plugin.
- Go to a empty directory
git clone https://github.com/NodeBB/nodebb-plugin-quickstart.git
You should have a folder called
nodebb-plugin-quickstart
Go into that directorycd nodebb-plugin-quickstart
and runsudo npm link
. More informations about that hereNo you can go into your nodebb installation and run
npm link nodebb-plugin-quickstart
Now ur plugin is linked to nodebb/node-modules and all modifications in
nodebb-plugin-quickstart
will appear in the linked folder inside your installation.Do only make changes in the downloaded folder, not inside nodebb/node-modules
Now you can edit the file
nodebb-plugin-quickstart/static/lib/main.js
You already should see this:
$(document).ready(function () { console.log('nodebb-plugin-quickstart: loaded'); });
Activate the plugin via ACP, rebuild nodebb and start it. No you should able to see
nodebb-plugin-quickstart: loaded
in the console of your webbrowser on refreshing the page.If you want to execute the function everytime not only on hard refreshing the page you can use:
$(window).on('action:ajaxify.end', function(data) { /*****/ });
Now you are able to make your API call with your own plugin.
Here are some usefull clientside hooks you can listen to, to execute your function.
-
@dogs themes are plugins, so everything you suggested can also be done in their theme.