En realidad, estoy usando nodemailer para enviar el código de plantilla html en el nodo js, pero el problema al que me enfrento es que no puedo anidar backlint en él:
Mi código:-
let mailDetails={ from: 'def@gmail.com', to: 'abc@gmail.com', subject: 'Order Confirmation Mail', html: `<html> //outer backlint start from here <body> <p id="s"></p> <script> const dataElement = document.querySelector('s'); const data = [ {url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: 'Nathan', price: 'Rs. 250', description: 'IRAN'}, {url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: 'Nathan', price: 'Rs. 250', description: 'IRAN'}, ]; data.map(item => { dataElement.insertAdjacentHTML('beforebegin', `<p>${item.name}</p>`)});//inner backlints </script> </body> </body> </html> `, //outer backlint end };Ps: - ignore los contenidos insertados por javascript ya que son datos ficticios. Solo quería mostrar el tipo de anidamiento que quería. Si uso ` entonces item.name queda indefinido e incluso al usar ${} sucedió.
Tienes que escapar del acento grave con \ . Este seria el resultado:
<html> //outer backlint start from here <body> <p id="s"></p> <script> const dataElement = document.querySelector('s'); const data = [ {url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: 'Nathan', price: 'Rs. 250', description: 'IRAN'}, {url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: 'Nathan', price: 'Rs. 250', description: 'IRAN'}, ]; data.map(item => { dataElement.insertAdjacentHTML('beforebegin', \`<p>${item.name}</p>\`)});//inner backlints </script> </body> </body> </html> Además, debe eliminar el segundo </body>
Hacer uso de ejs https://www.npmjs.com/package/ejs hará que dichas plantillas sean realmente rápidas. Lo estoy haciendo usando ejs.
ejemplo.js
let mailDetails = { from: 'def@gmail.com', to: 'abc@gmail.com', subject: 'Order Confirmation Mail', html: ejs.render("<path_to_ejs_template/template.ejs>"), //<-- replace this line with correct path to template.ejs };plantilla.ejs
<html> <body> <p id="s"></p> <script> const dataElement = document.querySelector("s"); const data = [ { url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: "Nathan", price: "Rs. 250", description: "IRAN", }, { url: "https://images.unsplash.com/photo-1593642633279-1796119d5482?ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60", name: "Nathan", price: "Rs. 250", description: "IRAN", }, ]; data.map((item) => { dataElement.insertAdjacentHTML("beforebegin", `<p>${item.name}</p>`); }); </script> </body> </html>