1

I want to code my Cartodb.js map so that for each marker, if a column is not empty, it embeds a video into the infowindow, and if the column is empty, then it does noting.I saw this example online and tried to copy it, but it didn't work. http://www.w3schools.com/js/js_if_else.asp

for my code, inside the {{content}} area, I said: if ({{video_embed_link}} IS NOT NULL) {< iframe width="430" height="242" src="{{video_embed_link}}" frameborder="0"> < /iframe>}

any suggestions on what to do instead?

4

Infowindows use Mustache templates, which don't allow for logic. You can do it with SQL(1) and some cleverness

SELECT 
  *, 
  CASE WHEN video_embed_link null THEN 0 ELSE 242 END AS video_height
FROM 
  table_name

Then, in your template, just do

< iframe width="430" height="{{video_height}}" src="{{video_embed_link}}" frameborder="0"> < /iframe>

Now, the iframe should be 0 pixels high if the embed link is NULL

1. I tend to say SQL can solve anything

0

Here's a simple CSS based solution which will work for iframes, images, links.

iframe[src=""],img[src=""],a[href=""] {
   display:none;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.