Dashboards & Visualizations

SimpleXML HTML tokens in HTML tag

fk319
Builder

I would like to create HTML code in my Splunk search and display it in an HTML section.
The problem I have is the interpreter presents my html as characters and not as tags.

In my current case, I have a series of image I would like to display, about 40. I can create the 40 set token in my SimpleXML, but it is so much easier to build it in the query. In the past I would have 1-3 images I wanted to display, but ended up only showing the first.


|eval html=""

gets displayed as the string.
I solved this by just passing

$result.icon$


Internally I have a multivalue field that has a list of icons, I would convert each to html and then join them up and pass as a single string. I just do not know how to display them as the intended tags instead of the string of characters.

0 Karma

paramagurukarth
Builder

There is no straight away solution for your requirement,
But you can achieve it via by adding some javascript with your token.

var defaultTokenModel = mvc.Components.get("default");
defaultTokenModel .on("change:your_token_name", function(tokenmodel, value, options ){
   /*
       Here based on your value you can construct your HTML and update the document
   */
})

You cannot use inline javscript inside splunk xml. you have to follow this doc

0 Karma

niketn
Legend

@fk319, From your question it is not crystal clear as to what you have and what you are trying to accomplish. However, if your goal is to set HTML in SPL and pass on to a <html> panel you can refer to the following answer by me with Simple XML JavaScript Extension: https://answers.splunk.com/answers/324828/render-html-code-from-search-result-in-splunk-dash.html

Please try out and confirm. If this is not what you need please elaborate with what you current have and mock up/details for what you need.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

fk319
Builder

I see what you are doing, but I need to do a js for each token I want to convert.
Is there a way I could do something more general? even if I could pas the id?

0 Karma

niketn
Legend

The Submitted Token object itself will have all the tokens available which you can iterate in a loop using JSON parse() method. However, before you even try that, I am unclear on your requirement. Can you please add more details/example or mock up screen for what you have and what you intend to implement?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

fk319
Builder

I did google search before I posted, really I did.
I like the solution. I will get the changed implemented in a few days. I am in documentation mode at the moment.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Deep Dive: Accelerate threat investigation with Splunk’s AI Assistant in Security

AI is one of the biggest topics in the market today, and for security teams, its value goes far beyond the ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Detection Engineering Office Hours: Real-World Troubleshooting & Q&A

[REGISTER HERE] This thread is for the Community Office Hours session on Detection Engineering Office Hours: ...