Jim
Jim

Reputation: 87

Can parameters to dust.js helpers be anything but a string (e.g. an array)?

While parsing JSON data with a dust.js template, I call a helper and pass an array from the JSON data to the helper as one of its parameters. It's an array of strings like:

"foo": ["a", "b", "c"]

Inside the dust.js helper the value becomes this string: "a, b, c". typeof reports its type as a string. Is there a way to thwart this automatic conversion? I don't want to do a split on the commas, because the individual strings in the array may contain commas.

Upvotes: 2

Views: 1113

Answers (1)

kate2753
kate2753

Reputation: 136

It depends how you pass in param into a helper. {@myHelpers arrayParam=myArray /} will be passed in as Array (granted that myArray is an Array) vs {@myHelper arrayParam="{myArray}"/} will be passed in as a String because of the interpolation. Note how first example does not have {} around myArray param.

Here is a working demo of these two examples in JSFiddle.

Upvotes: 2

Related Questions