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 - using pre-made helpers, can you split on two characters? #384

Closed bryllyg closed 3 years ago

bryllyg commented 3 years ago

I don't think this is possible, but can you use the split helper to split a string at two different characters? For example, if the string is:

44554- Text one;85554- Text two;

Can you split it at both the "-" and the ";"

Or, is there some other way to approach this, using pre-created helpers?

Any insight appreciated.

Devilthehell commented 3 years ago

Hey @bryllyg,

Sorry, I am new to GitHub, so if anything I do is incorrect, take it lightly =) Hope to help out though.

My first attempt was:

{{split (each (split "44554- Text one;85554- Text two;" ";")(.)) "-"}}

It failed, as the "each" was having issues...

Afterwards, I tried:

{{split (join (split "44554- Text one;85554- Text two;" "- ") ";") ";"}}

Because the first Split creates an array. We have to Join it. Then we can Split again on all the dashes. Resulting in: 44554,Text one,85554,Text two, Technically they are an array of strings.

I hope this helps. What is your field of work btw? I am a MIS admin, where we generate documents, using handlebars.

bryllyg commented 3 years ago

@Devilthehell Works like a charm! Thanks!

jonschlinkert commented 3 years ago

@bryllyg that's great! I'm glad this worked for you, and thanks @Devilthehell for the suggestion.

@bryllyg I'm going to go ahead and close since it seems like this resolved your question. please reopen if necessary.