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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...