Lee
Lee

Reputation: 533

How to get Pug template to send the variable value to email application instead of variable name?

How can I write 'mailto' in a Pug template in a way that the user automatically gets the real email value in his default email application when he clicks on the email? Writing it in this way:

a(href=`mailto:#{user_email}`) Send an email

gets the string #{user_email} in the email field, instead of the variable value.

Upvotes: 2

Views: 1993

Answers (2)

Yohan W. Dunon
Yohan W. Dunon

Reputation: 530

Three years ago this answer was valid but I think is deprecated. Not working for me.

You can find more in this answer => Original Answer

Here's the kicker :

const from = '[email protected]'

a(href=`mailto:${from}`, target='_blank', ...) Answer to #{from}

You can see the use of backticks plus the dollar sign.

Simple Template literals => MDN

🖖

Upvotes: 1

Lee
Lee

Reputation: 533

I found it! Within a link I should have directly read from the source, like this:

a(href=`mailto:`+ user.email) Send an email

Upvotes: 3

Related Questions