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: Query custom category objects (via template helper only)
# Configure DocPad
docpadConfig =
templateData:
# Get a collection of documents with a particular category
# Using QueryEngine's setFilter
getDocumentsWithCategory: (desiredCategory) ->
resultCollection = @getCollection('documents').createChildCollection()
.setFilter 'category', (model) ->
categories = model.get('categories')
return false unless Array.isArray(categories)
for category in categories
if desiredCategory in [category.id, category.slug]
return true
return false
.query()
return resultCollection
# Export
module.exports = docpadConfig
<%- @getDocumentsWithCategory('a').pluck('title') %>
title: 'Happy new year!'
layout: 'post'
categories: [
		id: 'a'
		description: 'a is the first letter of the alphabet'
	,
		id: 'b'
		description: 'b is the second letter of the alphabet'
]

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.