# Handlebars syntax in TSVB Markdown panel with conditional output for multiple items?

**URL:** <https://discuss.elastic.co/t/handlebars-syntax-in-tsvb-markdown-panel-with-conditional-output-for-multiple-items/273797>\
**Category:** Kibana\
**Created:** [May 24, 2021, 8:52am UTC](https://discuss.elastic.co/t/handlebars-syntax-in-tsvb-markdown-panel-with-conditional-output-for-multiple-items/273797 "2021-05-24T08:52:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GrahamHannington](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grahamhannington/32/4404_2.png) [@GrahamHannington](https://discuss.elastic.co/u/GrahamHannington)\
**Post date:** [May 24, 2021, 8:52am UTC](https://discuss.elastic.co/t/handlebars-syntax-in-tsvb-markdown-panel-with-conditional-output-for-multiple-items/273797/1 "2021-05-24T08:52:34Z")

</div>

### Background

I have two dashboards:

- **Dashboard A** is designed to present information about _multiple_ items.
- **Dashboard B** is designed to present information about _one_ of those items.

Visualizations in dashboard A drill-down to dashboard B: when the user clicks an item in dashboard A, the user is presented with an option to go to dashboard B, filtered by that item.

While dashboard B is _intended_ to show information about a single item, users could also choose to bypass the drill-down from dashboard A, and go directly to dashboard B.

More specifically, the items on these dashboards are "jobs", identified by a `job_name` field.

In dashboard B, I want to show `job_name` as a heading, because I don't feel that the filter is prominent enough.

I have a TSVB Markdown panel with the following details:

Aggregration: Count  
Group by: Terms  
By: `job_name`

The resulting objects accessible via Handlebars expressions have a `job_name` value as their first qualifier. For example, given a `job_name` value of `MASTER`, then the following Handlebars syntax:

```auto
{{ master.label }}

```

results in the Markdown panel displaying the string:

> MASTER

More usefully, if the dashboard is filtered to show only a single `job_name`, then the following combination of Markdown and Handlebars syntax:

```auto
## Job name: {{#each _all}}{{label}} {{/each}}

```

results in the heading:

> ## Job name: MASTER

However, if the dashboard _isn't_ filtered to show a single `job_name`, then "Job name: " is followed by numerous job names. I don't want that.

## Question

In a TSVB Markdown panel, can I use Handlebars syntax to test for the presence of multiple values of `job_name`, and then, if multiple values are found, display a message recommending that the user creates a filter; otherwise, as now, display the single job name in a heading?

Even after reading the [Handlebars documentation](https://handlebarsjs.com/guide/), I don't know how to do this, or even if it's possible.

My fuzzy idea is to use the built-in helper `#if` to test the number of "children" (first-level keys) of `_all`. (I understand that `_all` is an object, not an array. There's no `length` property here.)

I know that I can use `@index`, like this (shows the index incrementing on each list item), but I'm not sure how this helps my use case:

```auto
{{#each _all}}
- {{label}} {{@index}}
{{/each}}

```

---

<div class="post-metadata">

**Author:** ![GrahamHannington](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grahamhannington/32/4404_2.png) [@GrahamHannington](https://discuss.elastic.co/u/GrahamHannington)\
**Post date:** [May 25, 2021, 1:43am UTC](https://discuss.elastic.co/t/handlebars-syntax-in-tsvb-markdown-panel-with-conditional-output-for-multiple-items/273797/2 "2021-05-25T01:43:07Z")

</div>

Some detailed docs on what helpers are available in sub-expressions would be useful here.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 22, 2021, 1:44am UTC](https://discuss.elastic.co/t/handlebars-syntax-in-tsvb-markdown-panel-with-conditional-output-for-multiple-items/273797/3 "2021-06-22T01:44:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
