Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

329
Vistas
How to display a video template if a "video" field exists in firestore?

Hello I'm trying to display a video using template literals everything is working fine but now I wish to hide the template if the video field in firestore is empty or doesn't exists

enter image description here

If the field video has the embbed value in firestore the video correctly displays

enter image description here

But if the field video doesn't have any value then the iframe tag still shows up and I'd like to hide it

Here is my code



const video  = document.getElementById('video');
let path3 = `Ludolab/offer/list/${idRef}/index/${idCon}/content`;
let collRef3 = db.collection(path3);
collRef3.onSnapshot((querySnapshot) => {
  video.innerHTML = '';
  querySnapshot.forEach((doc) => {
    video.innerHTML +=`  
    <iframe class="has-ratio" width="150" height="150" src="https://www.youtube.com/embed/${doc.data().video}" 
            frameborder="0" allowfullscreen> 
    </iframe>
                         
        `
  });
});

Any help is gladly appreciate it, thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add a simple if statement that adds another iframe only when video field is present:

collRef3.onSnapshot((querySnapshot) => {
  video.innerHTML = '';
  querySnapshot.forEach((doc) => {
    if (doc.data().video) {
      // video field present, add iframe
      video.innerHTML += `  
    <iframe class="has-ratio" width="150" height="150" src="https://www.youtube.com/embed/${doc.data().video}" 
            frameborder="0" allowfullscreen> 
    </iframe>`
    }
  });
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda