Dynamic text plugin - refer to data elements

I’m using the Dynamic Text plugin to build a visualization in Grafana and need to get all the distinct values in the field hostname.
I can get all values with:

{{#each data}} {{hostname}} {{/each}}

Is there a way to get only the distinct values @mikhailvolkov ?

@goncalobsantos Depending on your data source, you can get a distinct hostname.

Transformations will be the next option, I am not sure if it’s possible.
3rd option is the JavaScript custom Handlebar definitely can do that.

Thanks @mikhailvolkov. I am currently exploring the third option, defining a custom Handlebar Helper. I can get a toy helper to work.
With the following in my Javascript:

handlebars.registerHelper("hostname", () =>
  [...new Set([host1, host1, host2])]);

and this in my content:

<div>{{hostname}}</div>

I get host1, host2 in my plugin, as desired. However, I can’t figure out the syntax to apply this same logic to the real case. With:

{{#each data}} {{"hostname.keyword"}} {{/each}}

I get all the hosts (including duplicates) in my plugin. So I am trying to pass this as the argument to my javascript function and was thinking that something like this should work. In my javascript:

handlebars.registerHelper("hostname", (allhosts) =>
  [...new Set(allhosts)]);

And this in my content:

<div>{{#hostname data}} {{"hostname.keyword"}} {{/hostname}}</div>

However, in my plugin this prints:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

I have also tried this in my content without success:

<div>{{hostname ({{#each data}} {{"hostname.keyword"}} {{/each}})}}</div>

Any other ideas?

@goncalobsantos It’s not the way how helpers work. Take a look at the examples in the documentation:

It should be something like that:

handlebars.registerHelper("unique", (context) =>
  return <<unique-values-from-the-context>>
);

Use:

<div>{{unique data}}</div>

Thank you for all your help @mikhailvolkov. Here’s what worked for me:

In my javascript, I defined this custom helper:

handlebars.registerHelper("unique", (context, key) => {
  return [...new Set(context.map(item => item[key]))];
});

And in my content:

<div>{{#each (unique data "hostname.keyword")}}{{this}}; {{/each}}</div>

This gives me a list of all the unique values in the hostname.keyword column of my dataframe.

@goncalobsantos Glad it worked!

I added your example in the plugin documentation