Accessing variables data from an HTML code block

Hi All,

I’m struggling with this a bit and haven’t found an exact answer. Is it possible to access variable data from the HTML block? I have some vars set and I have some JS rendering dynamic content based on the variables, but I cannot seem to actually get the data into the HTML block.

Any ideas?

Thanks.

Yes I made some videos about bridging between js land and weweb:

Bridging Weweb and Javascript Variables in under 15 minutes

@raydeck thanks for this. Your video was one of the first things I looked at, however, it doesn’t seem like I’m able to directly access the wwLib vars in the normal HTML editor?

If you are writing js in the block you can access using that technique - or should be able to. Can you share more about the problem?

It just seems like nothing happens at all when using the HTML element. For example, this code should print the content of the variable to console, but it does nothing:

<script>
// Retrieve the musicData using the correct WeWeb method and log it to console
try {
    const printData = wwLib.wwVariable.getValue("my var id");
    console.log('Print Data:', printData);
} catch (error) {
    console.error('Error accessing data:', error);
}
</script>

I’ve even tried accessing the variable and just displaying it on the page directly, but nothing. There’s a good chance I’m doing something wrong this with method. Though, if I bind the block to some JS that takes the vars as input and renders the HTML as a return string, then it works fine. It’s a little clunky to do it this way - but I’m wondering if I’m missing something obvious?