<% function render_category_chain(cat) { %>
  <a href="<%= url_for(cat.path) %>" class="category-chain-item"><%= cat.name.trim() %></a>
  <% var nextCats = categories.find({ parent: cat._id }).sort(config.index_generator.order_by || 'name').filter(cat => cat.length) %>
  <% if (nextCats.length > 0) { %>
    <span>></span>
    <%- render_category_chain(nextCats.data[0]) %>
  <% } %>
<% } %>

<span class="category-chains">
  <% 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) { %>
      <span class="category-chain">
        <%- render_category_chain(cat) %>
      </span>
    <% } %>
  <% }) %>
</span>