Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active December 11, 2015 05:58
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save balupton/4555641 to your computer and use it in GitHub Desktop.
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