Skip to content

Instantly share code, notes, and snippets.

@balupton balupton/README.md
Last active Dec 11, 2015

Embed
What would you like to do?
DocPad: Querying custom categories (via single categories object)
# ...
templateData:
categories:
a:
slug: 'a'
description: 'first letter of alphabet'
b:
slug: 'b'
description: 'second letter of alphabet'
getDocumentsForCategory: (categoryId) ->
return @getCollection('documents').findAll(categories: $has: categoryId)
getCategoriesForDocument: (document) ->
document ?= @getDocument()
categoryIds = document.get('categories')
categories = @categories[categoryId] for categoryId in categoryIds
return categories
# ...
title: 'Happy new year!'
layout: post
categories: ['a','b']

Happy new year. Boom boom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.