It makes sense that your data-vimeo-id is not showing – you are not instructing it to do so. You have setup a custom data attribute, but that is not how you display something on the page – you’ll want to look at Dynamic Attributes and the Inner Text of a div to display it.
But since the value is there, I suspect it is just a timing issue. In other words, the value is evaluated after the vimeo script has run.
Try setting up a flow. That flow will call the javascript function you create. The flow can be triggered through a dynamic event on app load.
Ya, I was only responding to the fact that you show " blank" in your screenshot when pointing to the div in your code -- just letting you know that it won't display without the inner text, not suggesting that displaying it will somehow fix this for you.
The flow needs to be triggered. On the App component, use a dynamic event on app ready, and run the flow.
You can also test the function in the developers console of your browser. On the console tab, just type the name of the function plus () and it will run the function. This is a good test because it removes the timing issue – good to know if the function is working on its own.
<script is="dmx-flow" id="flow1" type="text/dmx-flow">{
runJS: {
function: "loadVideo",
args: ["{{vimeo_id.value}}"]
}
}</script>
<dmx-value id="vimeo_id" dmx-bind:value="480055386"></dmx-value>
<div id="video1"></div>
<script src="https://player.vimeo.com/api/player.js"></script>
<script>
function loadVideo(vimeo_id) {
var options01 = {
id: vimeo_id,
width: "900px"
};
var video01Player = new Vimeo.Player('video1', options01);
video01Player.setVolume(0);
video01Player.on('play', function() {
console.log('Played the first video');
});
}
</script>
<script src="bootstrap/4/js/popper.min.js"></script>
<script src="bootstrap/4/js/bootstrap.min.js"></script>
It consists of a variable – this holds the vimeo id. Using a var is just an easy way for me to provide a value from app connect–using other dynamic data will work as well.
There is a function loadVideo that takes one parameter, the vimeo_id.
There is a flow. When run it calls the javascript function and passes it the value from the var.
There is a trigger on app ready, that runs the flow.
The above things cause: player.js:2 Uncaught (in promise) Error: An id or url must be passed, either in an options object or as a data-vimeo-id or data-vimeo-url attribute.
But I got it working: by putting the a dynamic event on the server connect itself. So when it’s done it triggers the flow that you’ve created
However now I’m dealing with another issue that the server connect is triggering twice, but I got another thread about that
create a function and call the function after server connect is loaded. In this way, the vimeo id will be available after the ID from server connect is ready.
@mebeingken this came in handy, however, are you only allowed to use dmx-bind: once per element? I am trying to add two custom data attributes to a button for use in a jQuery script and the first one renders as expected but the second doesn’t render at all.
@mebeingken thanks for the quick reply. I emptied the cache and it’s still the same. It’s the correct input because when I console.log each attribute’s value, the id value is correct and name is undefined.
I thought maybe it didn’t like “data-” in the attributes so I removed that, no difference. I tried to separate them with another by putting the dmx-on: code between them, still no go.
Kinda dead in the water without both attributes haha.
I created a sandbox page with just a server connect and a button…works fine. Try doing that, and if it works, you can find what is unique about your situation.