helpers / handlebars-helpers

188 handlebars helpers in ~20 categories. Can be used with Assemble, Ghost, YUI, express.js etc.
http://assemble.io/helpers/
MIT License
2.22k stars 365 forks source link

[Question] Is there a way to get a count of a subset of the results #378

Open bryllyg opened 3 years ago

bryllyg commented 3 years ago

Hi,

I still learning what I can and can't do in handlebars. I'm trying to figure out if I can get a count of a subset (filtered by field value) of the search query. For example, if I search for 'Engagements' and it returns 120 items, I would like to then be able to show that within those 120 items 23 are 'Active'. I've read through the handlebars info and tinkered, but I'm not sure this is doable with the helpers provided. Am I missing something? Thanks for any advice!

H

Devilthehell commented 3 years ago

Hey @bryllyg,

I think you might be able to get a count on how many are active by plucking the data, stringifying the array and then counting the occurrences of "Active"

{{occurrences (stringify (pluck Engagements "Status")) "Active"}}

Please bear with me, if my response is not proper, I am new to Github. Any recommendations on a better response format would be appreciated.

bryllyg commented 3 years ago

Hi @Devilthehell, Thanks! That's very helpful. I don't currently have access to pluck (it's not in the build of PnP Search I'm working with) but I'll get in a request for it :-)