I've been working on a section of a custom query and can't seem to get it to render the data.
In the Model section I have:
{
"iconUrl": {{ defaultIconColor.data.iconUrl }}
}
In the html section I have:
<!DOCTYPE html>
<html>
<head>
<title>SVG Data Fetch</title>
</head>
<body>
<div id="content">This is a test content to ensure the body is rendered.</div>
<div id="svgData">Initial SVG Data</div>
<div id="replacetest">Initial replacetest</div>
<div id="iconURL">Initial Icon URL</div>
<script>
async function fetchAndDisplaySVG() {
document.getElementById('content').innerText = "Starting fetchAndDisplaySVG";
try {
// Trigger the defaultIconColor query
await window.Retool.triggerQuery('defaultIconColor');
document.getElementById('replacetest').innerHTML = "boo";
} catch (error) {
document.getElementById('content').innerText = "Error in fetchAndDisplaySVG: " + error;
}
}
// Call the function to fetch and display the SVG data
fetchAndDisplaySVG();
// Subscribe to model updates
window.Retool.subscribe(function (model) {
document.getElementById("svgData").innerHTML = model.defaultIconColor || "No data available";
});
</script>
</body>
</html>
I set up a js query rendering the same results and it works fine:
// Function to set the default icon color
async function defaultIconColor() {
const color = "#808080"; // Default color
const defaultIcon = "house"; // Default icon
// Access the appropriate SVG from the global object and replace the placeholder with the actual color
let selectedSvg = window.iconsSVGs[defaultIcon];
if (selectedSvg) {
selectedSvg = selectedSvg.replace(/COLOR_PLACEHOLDER/g, color);
} else {
throw new Error('Default icon not found.');
}
// Convert the modified SVG content to base64
const base64Svg = btoa(unescape(encodeURIComponent(selectedSvg.trim())));
const iconUrl = `data:image/svg+xml;base64,${base64Svg}`;
return { iconUrl };
}
// Call the function and return the new icon URL
const newIconUrl = await defaultIconColor();
return newIconUrl;
The data output here looks something like this:
iconUrl:"data:image/svg+xml;base64,PD94bW..."
What am I doing wrong in the html script?