首页 > 解决方案 > Mailchimp API 和 mc:repeatable

问题描述

我正在使用 MailChimp Transactional API,但在填充使用 mc:repeatable 部分的电子邮件模板时遇到问题。我找不到有关如何执行此操作的任何文档或示例。这是使用https://mailchimp.com/developer/transactional/api/messages/send-using-message-template/的端点

这是我的电子邮件模板

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Your Order</title>
</head>
<body>
  <div>Thanks for your order</div>
  <div>Your receipt for your order from</div>
  <div mc:edit="store_name">Store Name</div>
  <div>Order Type</div>
  <div mc:edit="order_type">Type</div>  
  <div>Products:</div>  
  <table>
    <tr mc:repeatable="products">     
      <td mc:edit="quantity">Quantity</td>
      <td mc:edit="product_name">Product Name</td>
      <td mc:edit="price">Price</td>
    </tr> 
  
  </table>  

</body>
</html>

我可以在请求正文中mc:edit使用它来填充所有区域:template_content

const content = [
                {
                    name: 'store_name',
                    content: 'Any Store Name'
                },
                {
                    name: 'order_type',
                    content: 'Pickup Order'
                },
                {
                    name: 'subtotal',
                    content: '$80.00'
                },
                {
                    name: 'taxes',
                    content: '$2.22'
                },
                {
                    name: 'fees',
                    content: '$0.00'
                },
                {
                    name: 'total',
                    content: '$82.22'
                }
            ]

quantity如果我添加对象,我什至可以在可重复部分中填充单行product_nameprice但我需要能够重复此部分并添加多个数量 > 产品名称 > 价格行。

任何建议或帮助或文档都会很棒,谢谢!

标签: mailchimpmailchimp-api-v3.0mailchimp-api-v3

解决方案


MailChimp 模板语言参考中,似乎不<tr>支持元素mc:repeatable。请参阅第三点(粗体)并注意,虽然<table> 块级元素,<tr> 但不是

mc:可重复

  • mc:repeatable用于为模板中的特定元素提供复制操作。
  • 语法:mc:repeatable.
  • 用于mc:repeatable块级元素(如<div><p>),但列表或内联元素(如<img><a><span>)除外。
  • mc:repeatable元素可以相互嵌套,但如果要这样做,请小心。我们不鼓励这种用途。
  • mc:repeatable可以在与 相同的元素上使用mc:edit,但嵌套mc:repeatable在下面mc:edit将呈现可编辑但不可重复的内容。
  • 如果要将样式应用于可重复容器元素或可重复容器中的元素,请使用类或内联应用它们。不要使用 id 属性。

如果它们确实有效,您可能需要mc:variant为子字段使用和每个产品的名称。像这样的东西:

<table>
    <tr mc:repeatable="products" mc:variant="product1">
        <td mc:edit="product1_quantity">Quantity</td>
        <td mc:edit="product1_product_name">Product Name</td>
        <td mc:edit="product1_price">Price</td>
    </tr>
    <tr mc:repeatable="products" mc:variant="product2">
        <td mc:edit="product2_quantity">Quantity</td>
        <td mc:edit="product2_product_name">Product Name</td>
        <td mc:edit="product2_price">Price</td>
    </tr>
    <tr mc:repeatable="products" mc:variant="product3">
        <td mc:edit="product3_quantity">Quantity</td>
        <td mc:edit="product3_product_name">Product Name</td>
        <td mc:edit="product3_price">Price</td>
    </tr>
</table>
const content = [
    {
        name: 'product1_quantity',
        content: '5'
    }, {
        name: 'product1_name',
        content: 'Some Product'
    }, {
        name: 'product1_price',
        content: '$49.99'
    }, 

    {
        name: 'product2_quantity',
        content: '1'
    }, {
        name: 'product2_name',
        content: 'Some Other Product'
    }, {
        name: 'product2_price',
        content: '$1,200'
    },

    {
        name: 'product3_quantity',
        content: '13'
    }, {
        name: 'product3_name',
        content: 'Some Third Product'
    }, {
        name: 'product3_price',
        content: '$17.50'
    }
];

如果这看起来不是用于从动态数据构建列表,那是因为我不认为它是。看起来它是一种轻松将样式导入 Campaign Builder 的工具

在构建器内部,有一个Product概念,其中包括您希望在电子邮件中发送的信息类型。构建器的教程表明,虽然Product部分是可重复的,但您需要将数据源连接到构建器,并且必须Products在设计时选择要包含的数据源。

使用产品内容块从您连接的在线商店添加项目。每个块都设计为包含产品名称、自定义描述、价格和号召性用语按钮。如果您在电子邮件设置中打开电子商务跟踪,您的报告将显示购买收入。

要使用产品块,请按照以下步骤操作。

  1. 单击产品块或将其添加到您的电子邮件中。如果您正在使用现有块,请跳至步骤 4。
  2. 在选择商店模式中,选择要从中添加产品的商店。如果您尚未连接商店,系统会提示您这样做。
  3. 单击要添加的产品。
  4. 在产品菜单中,根据需要编辑标题、按钮和指向 URL 的链接。您还可以单击编辑图标选择不同的产品,或单击设置图标检查您的商店连接。

推荐阅读