[英]Pass variable to href tag within body of an email
First time posting, although I have spent many a moon lurking around the site.第一次发帖,虽然我花了很多时间在网站上潜伏。 I was unable to find if anyone had a similar post and thus I am posting to see if someone can answer this question for me.
我无法找到是否有人有类似的帖子,因此我发帖看看是否有人可以为我回答这个问题。
I am trying to embed a hyperlink into the body of an email.我正在尝试将超链接嵌入到 email 的正文中。 I am taking data from a specific cell from a sheet
我正在从工作表中的特定单元格获取数据
var n = ws.getRange("A2").getDisplayValue();
var data1 = ws.getRange("L2").getDisplayValue();
and want to pass that variable, data1 , to an html template to embed into a specific href tag URL within the template to mail out.并希望将该变量data1传递给 html 模板,以嵌入到模板中的特定 href 标记 URL 以邮寄出去。
var temp= HtmlService.createTemplateFromFile("xyz");
temp.name = n;
var htmlMessage = temp.evaluate().getContent();
GmailApp.sendEmail(
Email,
Subject,"Your email doesn't support HTML.",
{name: "AD", htmlBody: htmlMessage}
);
Example html file "xyz":示例 html 文件“xyz”:
<p>Hi, <?= name ?>,</p>
<p>Please see attached <a href="data1">link</a></p>
How would I go about passing the variable into the tag?我将如何 go 将变量传递到标签中? Thanks in advance!
提前致谢!
I believe your goal as follows.我相信你的目标如下。
data1
to data1
of <p>Please see attached <a href="data1">link</a></p>
.data1
的值放入<p>Please see attached <a href="data1">link</a></p>
的data1
中。 I think that in your situation, the scriptlets of <?=... ?>
and <?.=..? ?>
我认为在您的情况下,
<?=... ?>
和<?.=..? ?>
的小脚本<?.=..? ?>
can be used. <?.=..? ?>
可以使用。 When this is reflected to your script, it becomes as follows.当这反映到您的脚本中时,它变成如下。
xyz.html
xyz.html
<p>Hi, <?= name ?>,</p>
<p>Please see attached <a href="<?= data1 ?>">link</a></p>
<?= data1?>
or <??= data1 ?>
can be used.<?= data1?>
或<??= data1 ?>
。Code.gs
Code.gs
var n = ws.getRange("A2").getDisplayValue();
var data1 = ws.getRange("L2").getDisplayValue();
var temp= HtmlService.createTemplateFromFile("xyz");
temp.name = n;
temp.data1 = data1;
var htmlMessage = temp.evaluate().getContent();
GmailApp.sendEmail(
Email,
Subject,"Your email doesn't support HTML.",
{name: "AD", htmlBody: htmlMessage}
);
Simply add a link in href=""
like below只需在
href=""
中添加一个链接,如下所示
<p>Please see attached <a id="dataLink1" href="#">link</a></p>
<script>
var data1 = ws.getRange("L2").getDisplayValue();
document.getElementById("dataLink1").href=data1;
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.