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

Can you use both split and unique, in that order? #386

Open bryllyg opened 3 years ago

bryllyg commented 3 years ago

Syntax and functionality question - The list I am querying has a field with multiple comma delimited values. I am trying to:

I can do one or the other, split the entry OR get unique, but I can't figure out a way to do both. Is it possible using the provided helpers?

I've tried variations using {{#each items as |item|}} {{#with {split fieldname ',') as |tag|}} {{#each unique tag}}

Any suggestions? Thanks!

Devilthehell commented 3 years ago

Hey @bryllyg,

I do not have a field that contains multiple values separated by a comma, so I went ahead and plucked values out of a column to re create the scenario:

{{#each (unique (pluck DepartmentItems "Group"))}}{{.}},{{/each}}

Where "(pluck DepartmentItems "Group")" is the array of values that contain duplicates. For your script, I would change

{{#with {split fieldname ',') as |tag|}}

to

{{#with (split fieldname ',') as |tag|}}

and

{{#each unique tag}}

to

{{#each (unique tag)}}{{.}},{{/each}}

Hope this helps. Let me know if it does, or if I need to do something differently. I didn't know about the ability of "as |item|" until now, but maybe it is just your system that allows it?

bryllyg commented 3 years ago

Thanks! I'll give it a go.