[英]How to create dynamic table row in sendgrid template
我想將帶有發票編號和多次交易的電子郵件發送給客戶。 但是我無法在sendgrid模板中生成多行。 我已經在模板中發送了數組數據,但是它不會生成多行。
我想知道sendgrid模板支持動態行生成。
我有一個模板,其中有2列和多行,第一列是產品名稱,即-product-第二列價格,即-price-。 我已經傳遞了兩列-product-和-price-的動力學值,但它在兩列數組中顯示未生成動力學值。
這是我正在使用的代碼段:
$mail->invoiceTamplate('X-SMTPAPI', '{"filters":{"templates":{"settings":{ "enable":1,"template_id":"test"}}},"sub":{--product--":["'.$product.'"],"--price--":["'.$price'"]}}');
最后,我找到了解決這種情況的方法。 當您傳遞了兩個或三個的動力學值時,您需要在傳遞模板之前進行其他處理。
考試:我有一個模板,其中有2列和多行,第一列是產品名稱,即-product-第二列價格,即-price-。 我已經為兩列-product-和-price-傳遞了動力學值。 因此,我們不需要在sendgird模板中傳遞兩個值,我們只需在模板中傳遞一個值,該值我們將所有數據都設置為字符串。
<?php
$html = "<table><tr><th>product</th><th>price</th></tr>";
foreach($datas as $data)
{
$html.="<tr><td>".$data['product']."</td><td>".$data['price']."</td></tr>";
}
$html .="</table>;
$table = $html;
$mail->invoiceTamplate('X-SMTPAPI', '{"filters":{"templates":{"settings":{ "enable":1,"template_id":"test"}}},"sub":{"--table--":["'.$table'"]}}');
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.