Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带条件行的HTML表_Html_Html Table_Handlebars.js - Fatal编程技术网

带条件行的HTML表

带条件行的HTML表,html,html-table,handlebars.js,Html,Html Table,Handlebars.js,我使用html模板向客户发送电子邮件。模板包含一个表,我需要这个表根据它接收的数据显示或隐藏行。使用把手将数据注入HTML 我尝试将条件if添加到表中,这在浏览器上可以正常工作,但在看到电子邮件时不行: <table class="tg"> <thead> <tr> <th class="tg-0pky">Name</th> <th cl

我使用html模板向客户发送电子邮件。模板包含一个表,我需要这个表根据它接收的数据显示或隐藏行。使用
把手
将数据注入HTML

我尝试将条件
if
添加到表中,这在浏览器上可以正常工作,但在看到电子邮件时不行:

<table class="tg">
   <thead>
      <tr>
         <th class="tg-0pky">Name</th>
         <th class="tg-0pky">{{ recipientName }}</th>
      </tr>
   </thead>
   <tbody>
      {{#if recipientId}}
      <tr>
         <td class="tg-0pky">ID</td>
         <td class="tg-0pky">{{ recipientId }}</td>
      </tr>
      {{/if}}
      {{#if recipientBank}}
      <tr>
         <td class="tg-0pky">Bank</td>
         <td class="tg-0pky">{{ recipientBank }}</td>
      </tr>
      {{/if}}
      {{#if recipientBranch}}
      <tr>
         <td class="tg-0pky">Branch</td>
         <td class="tg-0pky">{{ recipientBranch }}</td>
      </tr>
      {{/if}}
      {{#if recipientAccountNumber}}
      <tr>
         <td class="tg-0pky">Account number<br/></td>
         <td class="tg-0pky">{{ recipientAccountNumber }}</td>
      </tr>
      {{/if}}
      {{#if recipientAccountType}}
      <tr>
         <td class="tg-0pky">Account type</td>
         <td class="tg-0pky">{{ recipientAccountType }}</td>
      </tr>
      {{/if}}
      <tr>
         <td class="tg-0pky">Amount to receive</td>
         <td class="tg-0pky">{{ recipientReceive }}</td>
      </tr>
   </tbody>
</table>

名称
{{recipientName}}
{{{#if recipientId}
身份证件
{{recipientId}
{{/if}
{{{#如果收款人银行}
银行
{{recipientBank}}
{{/if}
{{{#如果recipientBranch}}
分支机构
{{recipientBranch}}
{{/if}
{{{#如果收件人帐号}
帐号
{{recipientAccountNumber}} {{/if} {{{#如果recipientAccountType} 帐户类型 {{recipientAccountType} {{/if} 收到的金额 {{recipientReceive}}
收到电子邮件时:

当我收到电子邮件时,将根据注入的数据显示行或不显示行,但表将丢失其格式

我已经读到使用脚本不是处理这个问题的最佳方式,因为在电子邮件中使用脚本不是一个好的做法


如果变量存在或不存在,我如何动态显示或隐藏行?

听起来您的问题与表格的样式有关,而不是与呈现的输出有关。但是如果我删除条件
if
,它只会呈现行。您是否在电子邮件中发送未编译的模板?!您希望编译模板,然后执行编译后的函数以生成要发送的电子邮件正文。这将需要在服务器端(使用节点)而不是在客户端(浏览器)中使用Handlebar。否,模板已接收变量。但是我发送的HTML就像在帖子里一样,我不知道你在说什么。我不知道您的电子邮件HTML是否包含把手模板标记(
{{{if recipientId}}
,等等)。