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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...