Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Unable to nest backlint( ` ) in html

Actually i am using nodemailer to send html template code in node js but the problem am facing is that am not able to nest backlint in it:-

My Code:-

    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 the contents being inserted by javascript as they are dummy data. Just wanted to show the type of nesting i wanted. If i use ` then item.name gets undefined and even on using ${} it happened.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to escape the backtick with \. This would be the result:

    <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>

Also, you should remove the second </body>

about 4 years ago · Juan Pablo Isaza Report

0

Making use of ejs https://www.npmjs.com/package/ejs will make such templating really quick. I am doing it using ejs.

example.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
};

template.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>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!