See http://stackoverflow.com/a/14381327/130638 for explanation.
Last active
December 11, 2015 05:59
-
-
Save balupton/4556245 to your computer and use it in GitHub Desktop.
DocPad: Query custom category objects (via template helper only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%- @getDocumentsWithCategory('a').pluck('title') %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment