Dashboards & Visualizations

Tokens in templates?

unclethan
Path Finder

I want to put a token into a panel-header and tried to use the token_safe filter as such:

{% filter token_safe %} The selected pool is $selectedPool$ {% endfilter %}

While this is valid in django (e.g. replace token_safe with lower), it is not translating my token.

What is the correct incantation?

1 Solution

magnew_splunk
Splunk Employee
Splunk Employee

Hello unclethan,

If I am understanding your scenario correctly, it is not currently supported out of the box in the framework using just Django. We don't currently support token replacement of arbitrary html elements. We can put the feature in consideration for a future release. In the mean time, you can probably achieve the behavior you want using JavaScript to listen to changes in the token model and update your panel header manually. To do this you'd first put the part of your header that you'd like to update in an identifiable <span> element--something like:

{% filter %} The selected pool is <span id="filter">Replaceable text</span> {% endfilter %}

Then, you'd listen to the token model in JavaScript and set the text of the span using JQuery when it changes:

mvc.Components.getInstance("default").on("change:selectedPool", function(model, value, options) {
    $("#filter").text(value);
});

That code gets the default token namespace, and listens to changes on the token called selectedPool. Then it sets the text of the filter span to the value of the selectedPool token.

I hope that helps.

View solution in original post

magnew_splunk
Splunk Employee
Splunk Employee

Hello unclethan,

If I am understanding your scenario correctly, it is not currently supported out of the box in the framework using just Django. We don't currently support token replacement of arbitrary html elements. We can put the feature in consideration for a future release. In the mean time, you can probably achieve the behavior you want using JavaScript to listen to changes in the token model and update your panel header manually. To do this you'd first put the part of your header that you'd like to update in an identifiable <span> element--something like:

{% filter %} The selected pool is <span id="filter">Replaceable text</span> {% endfilter %}

Then, you'd listen to the token model in JavaScript and set the text of the span using JQuery when it changes:

mvc.Components.getInstance("default").on("change:selectedPool", function(model, value, options) {
    $("#filter").text(value);
});

That code gets the default token namespace, and listens to changes on the token called selectedPool. Then it sets the text of the filter span to the value of the selectedPool token.

I hope that helps.

unclethan
Path Finder

Thanks, this worked out.

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...