As a result, I got such a script, maybe it will be useful to someone.
const Theme = {} const user = require.main.require('./src/user') const privileges = require.main.require('./src/privileges') Theme.getUsersByCategory = async function(data) { const { templateData: { cid } } = data const allUserIds = await user.getUidsFromSet('users:joindate', 0, -1) const asyncFilter = async (arr, predicate) => { const results = await Promise.all(arr.map(predicate)) return arr.filter((element, index) => results[index]) } const availableUserIds = await asyncFilter(allUserIds, async (id) => { return await privileges.categories.can('read', cid, id) }) data.templateData.availableUsers = await user.getUsersData(availableUserIds) return data } module.exports = ThemeGet topics in category?
-
Use jQuery to get the topics from the API.
<div id="mycats"></div> <script> $.getJSON('/api/category/1', function (data) { for (var i in data.topics) { $('#mycats').append('<div>' + data.topics[i].title + '</div>') } }) </script>
-
It would, technically. You would have to make your own widget plugin to add the data to the widget template, or add a widget to widget-essentials. Using
Categories.getCategoryTopics
psuedo example, check out widget-essentials for all needed code.
Plugin.renderMyTopicsWidget = function(widget, callback) { Categories.getCategoryTopics({ cid: widget.req.params.cid || 1, // or whatever category ID you want. set: 'cid:' + widget.req.params.cid + ':tids', reverse: true, start: 0, stop: 10, uid: widget.uid }, function(err, result) { widget.data.topics = result app.render('widgets/yourwidget', widget.data, function(err, html) { translator.translate(html, function(translatedHTML) { callback(err, translatedHTML) }) }) }) }
widgets/yourwidget.tpl
<!-- BEGIN topics --> <div>{topics.title}</div> <!-- END topics -->