Dmx.parse Not workin

Hello,

I’m using dmx.parse and it’s not working correctly.

I have the following lines of code:

<dmx-value id="var1" dmx-bind:value="'hello'"></dmx-value>

<script>
   
    let myVar = dmx.parse('var1.value');
    console.log(myVar);

</script>

When I load the page I get “undefined” on chrome and after loading the page I type on Chrome’s console and get the same undefined error.

Any ideas? The variable it’s declared before executing the script.

Your script is likely running before app connect is loaded. The solution depends on your specific need but you can create a function, or use the app ready events, use a flow etc.

Many solutions, but it’s probably just timing.

1 Like

I’ve done that before. And when I use Chrome’s console I’m basically running dmx.parse('var1.value') and it’s not working either (although I run it after loading the page)

Use dmx.app.data to confirm the path to the variable. People often miss things like it being in a content page. Also, I always use double quotes for parse but I’d be surprised if your use of single quotes is the issue.

I’ve changed var1 to var2 because it’s was being used on the layout page.

This is my new code:

<dmx-value id="var2" dmx-bind:value="'hello'"></dmx-value>

<script>
let myVar = dmx.parse('var2.value');
console.log(myVar);
</script>

Yet, var2 is not appearing in dmx.app.data path:

UPDATE, var2 appears under content

Right, so add content before var2.

2 Likes

Thank you for your time!!!

1 Like

Now I understood what’s happening. When using a content page inside a layout, from JS all content variables will be inside dmx.app.data.content… :face_with_monocle: