In Foundry Slate, how do I dynamically index into an array or object using handlebars?

354 Views Asked by At

In Foundry's Slate application, I'd like to index into an array or other object based upon some seletion in another widget -- say, choosing a column from a dropdown.

How can I accomplish something like this?

1

There are 1 best solutions below

0
On

You can use the lookup handlebars helper reference.

The lookup helper looks like the following {{lookup arrayName index}} and is equivalent to arrayName[index] in javascript.

This also works for objects as {{lookup objectName key}}.

And you can do it for nested things as well:

{{lookup a "b" "c"}}

where the context is { a: { b: { c: "test" } } }

Will return "test"

To simplify things, you can also write a small helper function that takes in the selection and the data, does any necessary work to produce the correct output and then returns that output to display elsewhere.