DEV Community

Chandra Prakash Pal
Chandra Prakash Pal

Posted on

Replace All String in mail templace

When we create a dynamic mail template,then we need to replace the dynamic value with desired key value pair.
Using the following method we can do that.

let mail=`
        <html>
            <body>
                <h1>Welcome, $username!</h1>
                <h1>Welcome, $address!</h1>
                <p>Thank you for signing up. We're glad to have you on board.</p>
            </body>
        </html>
    `
const info={
    username:"Chandra",
    address:"Saket Nagar"
}

for(let rinfo in info){
    console.log(rinfo,info[rinfo])
    mail=mail.replace('$'+rinfo,info[rinfo])
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)