You might also need to include content before anything if the item is in a content page, rather than layout. This might actually be why your parse doesn’t work (you can use either).
This is weird, dmx.app.data only contains variables that are defined in the main layout, not in the content page
I think I’m not following Thanks for your insights though! (edit: just understood it)
I got it working, turns out content variables are in dmx.app.data.content. It’s not possible to edit this directly though (else it’ll break stuff), one needs to use dmx.app.set('pageLoaded', 1)
Actually, it’s kind of a broken mess. It only works if I do:
(from 1 to 0)
dmx.app.data.content.pageLoaded = 0; // this line alone doesn't trigger view changes
dmx.app.set('pageLoaded', 0); // triggers view changes, only if line before was executed
How am I supposed to edit this variable?
Edit: How to access dmx.app.data.content.pageLoaded using dmx.app.get?
I want to show this <div> once a certain Javascript code (unrelated to Wappler) executes succesfully, at which point I want to make pageLoaded.value = 1.
For testing purposes, this variable is set to 1 by default:
The aim is to make it hide by doing pageLoaded.value = 0
If I do this:
dmx.app.data.content.pageLoaded = 0;
The div was supposed to hide, but that doesn’t happen, unless I execute the following line after:
dmx.app.set('pageLoaded', 0);
But this ‘pageLoaded’ variable didn’t seem to exist, because dmx.app.get returned undefined before the set. So, the dmx.app.set is there just to refresh the view (i.e.: make dmx-show update), which looks like a bit ugly solution
If possible refactor your JS code into an AC component so you don’t have to deal with these things which can over-complicate over time when you need to make sure that AC library is initialised before calling certain functions.
For example in my i18next AC component I have to avoid some flickering of the strings while being translated so I hide the body until the i18next component is initialized.
i18next.on('initialized', function (options) {
dmx.requestUpdate()
this.dispatchEvent('init')
this.set("init", true)
// We overwrite the formatter as the library has been initialized.
dmx.Formatter('string', 't', function (key, options) {
console.log("Translated: " + key)
return i18next.t(key, options)
});
}.bind(this));
Then I just check the variable init I just set for my i18next component to show the body.