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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...