2

How is it possible to embed content — like YouTube-Videos, Twitter-Tweets, Facebook-Posts, Instagram-Photos or any other kind of embeds — into a InfoWindow in CartoDB?

In my Dataset there is a row with the embed-code (iframe, script etc.) and I included the field into the infowindow via the CartoDB-Wizard … I know CartoDB blocks every script etc. … but there should be something like a «sanitizeTemplate» through CartoDB.js (as this was posted from someone in another question) — but I'm not able to get this working properly … can someone help me please? … with a detailed/full example?

3

By using CartoDB.js you can set sanitizeTemplate as false in order to run your scripts inside custom infowindows.

An example:

cartodb.createVis('map', 'viz_json', {options})
.done(function(vis, layers) {
   var d = layers[1].getSubLayer(0);
   d.infowindow.set({sanitizeTemplate:false});
   d.infowindow.set("template", function(g) { ... });
5
  • THX! … I guess I stumbled over layers[1].getSubLayer(0) … is there a way to apply this to ALL layers of this vis?
    – albuvee
    Jun 23 '15 at 12:18
  • … first it worked, now not anymore!? … and now it displays only the raw-html: pasteboard.co/1r8hCUcT.png … code: pasteboard.co/1r8jDCSx.png
    – albuvee
    Jun 23 '15 at 12:34
  • 1
    The functions for setting the infowindows expect to be applied over a specific layer, so you'd need to repeat the code for each layer.
    – iriberri
    Jun 23 '15 at 12:38
  • Alright, I think I have the solution … instead of {{embed}} in the custom template write {{{embed}}} … then it works. Why? … don't know ;-)
    – albuvee
    Jun 23 '15 at 12:43
  • 1
    {{{column}}} returns unescaped HTML in Mustache :-)
    – iriberri
    Jun 24 '15 at 8:57

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .