Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda