Reputation: 5254
I'm really confused about this. I'm using Cincopa to create and embed image galleries onto my Meteor site.
This works. The gallery shows up on page load.:
<template name="test">
<!-- Image Gallery Embed Code -->_
<div id="cp_widget_a718e3a7-4a35-4f13-b14e-299cc73c6ecb">...</div>
<script type="text/javascript">
var cpo = [];
cpo["_object"] = "cp_widget_a718e3a7-4a35-4f13-b14e-299cc73c6ecb";
cpo["_fid"] = "A4IAkTttPOWL";
var _cpmp = _cpmp || [];
_cpmp.push(cpo);
(function() {
var cp = document.createElement("script");
cp.type = "text/javascript";
cp.async = true;
cp.src = "//www.cincopa.com/media-platform/runtime/libasync.js";
var c = document.getElementsByTagName("script")[0];
c.parentNode.insertBefore(cp, c);
})();
</script>
<!-- Image Gallery Embed Code -->_
</template>
This does not. Nothing but the empty <div>
with ...
shows up. There are no error messages.
<template name="test">
<div id="cp_widget_a718e3a7-4a35-4f13-b14e-299cc73c6ecb">...</div>
</template>
JS:
Template.test.onRendered(function(){
var cpo = [];
cpo["_object"] = "cp_widget_a718e3a7-4a35-4f13-b14e-299cc73c6ecb";
cpo["_fid"] = "A4IAkTttPOWL";
var _cpmp = _cpmp || [];
_cpmp.push(cpo);
(function() {
var cp = document.createElement("script");
cp.type = "text/javascript";
cp.async = true;
cp.src = "//www.cincopa.com/media-platform/runtime/libasync.js";
var c = document.getElementsByTagName("script")[0];
c.parentNode.insertBefore(cp, c);
})();
});
It's the exact same code...
Am I missing something with how Meteor loads things?
Upvotes: 0
Views: 62
Reputation: 75945
You need to make those variables available in the global scope for the script to access them:
Change
var _cpmp = _cpmp || [];
Remove the 'var' keyword and use window instead
window._cpmp = window._cpmp || [];
Upvotes: 1