<% function render_category_chain(cat) { %> <%= cat.name.trim() %> <% var nextCats = categories.find({ parent: cat._id }).sort(config.index_generator.order_by || 'name').filter(cat => cat.length) %> <% if (nextCats.length > 0) { %> > <%- render_category_chain(nextCats.data[0]) %> <% } %> <% } %> <% var catsFirst = categories.find({ parent: { $exists: false } }).sort(config.index_generator.order_by || 'name').filter(cat => cat.length) %> <% catsFirst.each((cat, idx) => { %> <% if (typeof(limit) === "undefined" || idx < limit) { %> <%- render_category_chain(cat) %> <% } %> <% }) %>