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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...