Sure.
library.js
Plugin = module.exports;
var categories = require.main.require('./src/categories');
// init hook
Plugin.init = function (data, callback) {
var router = data.router;
var middleware = data.middleware;
// Create route to render the template to.
router.get('/example-categories', middleware.buildHeader, renderExampleCategories);
router.get('/api/example-categories', renderExampleCategories);
function renderExampleCategories(req, res, next) {
// Get all the visible categories.
categories.getCategoriesByPrivilege('cid:0:children', req.uid, 'find', function(err, categoryData) {
if (err) return next(err);
// Put the categories in a tree format.
categories.flattenCategories([], categoryData);
// Send the data to the template. `example-categories.tpl`
res.render('example-categories', {categories: categoryData});
});
}
};
example-categories.tpl
<!-- BEGIN categories -->
<a href="{config.relative_path}/category/{categories.slug}" itemprop="url">{categories.name}</a> <br>
<!-- BEGIN categories.children -->
- <a href="{config.relative_path}/category/{categories.children.slug}" itemprop="url">{categories.children.name}</a> <br>
<!-- END categories.children -->
<!-- END categories -->
Should give you a list like this