Logicify / mautic-advanced-templates-bundle

Plugin extends default email template capabilities with TWIG block so you can use advanced scripting techniques like conditions, loops etc
https://logicify.com/?utm_source=github&utm_campaign=mautic-templates&utm_medium=opensource
MIT License
86 stars 57 forks source link

JSON Scripting Issue - TWIG outputs does not match RAW data. #25

Open kurtispsmith opened 2 years ago

kurtispsmith commented 2 years ago

I'm seeing several scenarios where the TWIG template is outputting the wrong values when I run campaigns.

In the example you can see the output data does not match the raw JSON data when you compare stocks #s.

SAMPLE: image

CODE:

<!-- INVENTORY SNIPPETS --> 
{% TWIG_BLOCK %} 
    {% set items = lead.c_inventory_json | json_decode %}
    {% for item in items %}
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="em_full_wrap" bgcolor="{contactfield=d_page_bgcolor}" style="table-layout:fixed;">
  <tr>
    <td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="em_full_wrap" bgcolor="{contactfield=d_page_bgcolor}" style=" table-layout:fixed;">
        <tr>
          <td align="center" valign="top"><table align="center" width="580" border="0" cellspacing="0" cellpadding="0" class="em_main_table" style="width:580px; table-layout:fixed; background-color: {contactfield=d_body_bgcolor};" data-section-wrapper="1">
              <tr>
                <td valign="top" align="center" data-section="1"><table width="580" border="0" cellspacing="0" cellpadding="0" align="center" style="width: 580px;" class="em_wrapper" data-slot-container="1">
                    <tbody>
                      <tr>
                        <td valign="top" align="center" style="padding: 0px 16px 16px 16px;" class="em_ptblr15"><div data-slot="text">
                            <table border="0" cellspacing="0" cellpadding="0" align="center" width="100%">
                              <tbody>
                                <tr>
                                  <td valign="top" align="center"><table border="0" cellspacing="0" cellpadding="0" align="left" width="267" style="width: 267px;" class="em_wrapper">
                                      <tbody>
                                        <tr>
                                          <td valign="top" align="center" class="em_full_img em_btn_butm"><a href="{{ item.VDP_URL }}" ses:tags="campaign:lead-accelerator-21d-new-inventory;content:explore-vehicle-cta;handraiser:yes;type:image" target="_blank" style="text-decoration: none;"><img src="{{ item.MainImage }}" width="267" alt="" style="display: block; border: 0px; max-width: 267px; color: #000000; font-size: 18px; line-height: 22px; font-family: Arial, sans-serif;" class="em_full_img" /></a></td>
                                        </tr>
                                      </tbody>
                                    </table>

                                    <!--[if gte mso 9]></td><td valign="top"><![endif]-->

                                    <table width="265" border="0" cellspacing="0" cellpadding="0" align="right" style="width: 265px;" class="em_wrapper">
                                      <tbody>
                                        <tr>
                                          <td height="35" style="height: 35px;" class="em_hide"></td>
                                        </tr>
                                        <tr>
                                          <td valign="top" align="center"><a ses:tags="campaign:lead-accelerator-21d-new-inventory;content:explore-vehicle-cta;handraiser:yes;type:button"  href="{{ item.VDP_URL }}?utm_source=3birds&utm_medium=email&utm_campaign={contactfield=c_customer_id}_leadaccelerator_21d_new_inventory" target="_blank" style="text-decoration: none;"> <span style="font-family: {contactfield=d_font_family}; color: {contactfield=d_body_color}; font-size: 16px; line-height: 17px;padding-bottom: 2px;"> {{ item.VehicleType }} {{ item.Year }} {{ item.Make }}</span><br>
                                            <span style="font-family: {contactfield=d_font_family}; color: {contactfield=d_body_color}; font-size: 25px; line-height: 17px;padding-bottom: 5px;"> {{ item.Model }}  {{ item.Trim1 }}</span></a></td>
                                        </tr>
                                        <tr>
                                          <td valign="top" align="center" style="font-family: {contactfield=d_font_family}; color: {contactfield=d_body_color}; font-size: 13px; line-height: 17px;padding-bottom: 19px;"> {{ item.Mileage }} miles<br />
                                            Stock #: {{ item.StockNumber }}<br /></td>
                                        </tr>
                                        <tr>
                                          <td valign="top" align="center"><table width="261" style="width: 261px;" border="0" cellspacing="4" cellpadding="0" align="center" class="em_wrapper">
                                              <tbody>
                                                <tr>
                                                  <td valign="middle" align="center" height="36" bgcolor="{contactfield=d_btn_bgcolor}" style="height: 36px; font-family: {contactfield=d_font_family}; color: {contactfield=d_btn_color}; font-size: 12px; font-weight: bold; border-radius: {contactfield=d_btn_radius}px;"><a ses:tags="campaign:lead-accelerator-21d-new-inventory;content:explore-vehicle-cta;handraiser:yes;type:button"  href="{{ item.VDP_URL }}?utm_source=3birds&utm_medium=email&utm_campaign={contactfield=c_customer_id}_leadaccelerator_21d_new_inventory" target="_blank" style="text-decoration: none; color: {contactfield=d_btn_color}; line-height: 36px; display: block;">GET TODAY'S PRICE</a></td>
                                                </tr>
                                              </tbody>
                                            </table></td>
                                        </tr>
                                      </tbody>
                                    </table></td>
                                </tr>
                              </tbody>
                            </table>
                          </div></td>
                      </tr>
                    </tbody>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
{% endfor %}
{% END_TWIG_BLOCK %} 
<!-- END INVENTORY SNIPPET --> 

JSON:

[ { "Vin": "WA1GAAFYXN2020549", "StockNumber": "125232", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbafeb80a0e09a863ce5adb3236638f", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/9d93fecf64c543749930a746798da91e.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1GAAFY0N2019569", "StockNumber": "125233", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbafd0f0a0e09a97fb17999bd212a47", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/1365fd683f3444bebf81e68861881a1c.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1EAAFY7N2020161", "StockNumber": "125234", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium Plus", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbafc8a0a0e09a97fb17999835188e2", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/d5dabe9bf25f442792ad52540cb4ca20.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1EAAFY2N2019550", "StockNumber": "125236", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium Plus", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbafaee0a0e09a97fb17999f2f624fc", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/0e12d14246a14377ae4a8f7858c03d05.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1EAAFY5N2019560", "StockNumber": "125235", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium Plus", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 11, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbafbcd0a0e09a97fb179992e604df1", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/bd4820362b2f4c9184d22d6ebbb94af9.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1EAAFY0N2019465", "StockNumber": "125238", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium Plus", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 11, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbaf9030a0e097120e50d484db79fd4", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/fe2abb1b45504cf0b81de4ae002fc323.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1EAAFY1N2020110", "StockNumber": "125237", "Make": "Audi", "Model": "Q5", "Trim1": "S line Premium Plus", "BodyStyle": "SUV", "Year": 2022, "VehicleType": "New", "IsCertified": false, "Mileage": 11, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=3bbaf9d40a0e09a97fb1799903d738dd", "DateInStock": "2021-10-09", "MSRP": 0, "DateCreated": "2021-10-09", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/038fb403ed0a4e9e840686330eea57c5.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2022AUS02_640/2022AUS020001_640_01.jpg" }, { "Vin": "WA1BAAFY6M2071281", "StockNumber": "124551", "Make": "Audi", "Model": "Q5", "Trim1": "Premium Plus", "BodyStyle": "SUV", "Year": 2021, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=2112a0f00a0e0a173e8f42ae818f0bb7", "DateInStock": "2021-04-02", "MSRP": 0, "DateCreated": "2021-09-30", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/9e052de1c6d34daaab9447fbe6cfef16.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2021AUS02_640/2021AUS020001_640_01.jpg" }, { "Vin": "WA1BAAFY5M2136783", "StockNumber": "125085", "Make": "Audi", "Model": "Q5", "Trim1": "Premium Plus", "BodyStyle": "SUV", "Year": 2021, "VehicleType": "New", "IsCertified": false, "Mileage": 10, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=f73d23280a0e09b1110b8372a5c9f31b", "DateInStock": "2021-08-13", "MSRP": 0, "DateCreated": "2021-09-30", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/406c5f03fc5b4c0ba41f35a92e27a3fb.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2021AUS02_640/2021AUS020001_640_01.jpg" }, { "Vin": "WA1BAAFY5M2031466", "StockNumber": "S124170", "Make": "Audi", "Model": "Q5", "Trim1": "Premium Plus", "BodyStyle": "SUV", "Year": 2021, "VehicleType": "New", "IsCertified": false, "Mileage": 45, "VDP_URL": "http://www.jackdanielsparamusaudi.com/catcher.esl?vehicleId=783855c20a0e0adf6a6e7a177787ba53", "DateInStock": "2020-12-18", "MSRP": 0, "DateCreated": "2021-09-30", "InternetPrice": 0, "MainImage": "https://content.homenetiol.com/640x480/186be7fe66c741e9ba9d9026127c0c83.jpg", "StockImage": "https://content.homenetiol.com/stock_images/5/2021AUS02_640/2021AUS020001_640_01.jpg" } ]

NOTE: IF I SEND THE SAME TEMPLATE TO THE SAME CONTACT USING THE "CONTACT > SEND EMAIL" FEATURE, IT WORKS JUST FINE. HOWEVER, WHEN I'M RUNNING BATCH CAMPAIGNS IT DOES NOT WORK. IT APPEARS THERE IS A STATE ISSUE WHERE THE SCOPE OF THE OBJECT IS NOT BEING RESET PER RECIPIENT.