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

171
Visualizações
Node js Replace Html table with daynamic data

I am stuck a bit with replacing strings in the HTML file through looping on the array. I am reading the HTML file it's a big template file attached to the email. I want to loop on data and replace HTML with dynamic data. But only one element is replacing.


<table cellpadding="10" cellspacing="0" width="600" align="center"
                                        style="border-collapse:collapse;background:white;">
                                        <tr>
                                            <td>
                                                <table cellpadding="0" cellspacing="0" width="600" align="left" border="1" id="myTable">
                                                    <tr>
                                                        <td>Date</td>
                                                        <td>%DateTo% - %DateFrom%</td>
                                                    </tr>
                                                    <tr>
                                                        <td>Url</td>
                                                        <td>%reportUrl%</td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
</table>


 let mailHtml = '';
  mailHtml = fs.readFileSync('app/emailTemplates/ReportTemplate .html').toString();
 dataValues.forEach(ele => {
                            mailHtml = mailHtml.replace('%DateTo%', ele.dateTo);
                            mailHtml = mailHtml.replace('%DateFrom%', ele.dateFrom);
                            mailHtml = mailHtml.replace('%reportUrl%', ele.reportUrl);
            
})

enter image description here

about 4 years ago · Juan Pablo Isaza
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