0

I get a json array into a single field in a DE. I am then using dataobject tags to get each tag out and render it in an email.

I am using drag and drop content blocks to make it easy for end-users to manage the style of the email. My dataobject code looks like this:

%%[
  /* Set the data extension field containing the array as a variable */
  VAR @productsArray SET @productsArray = Products
]%% 

%%[/* Define the array to parse and create the data object */]%%
{{.dataobject productsData type=variable source=@productsArray}} 
  {{.data}} 
    {
      "target":"@productsArray"
    } 
  {{/data}} 
{{/dataobject}}

{{#each productsData}}    

%%[/* Set some variables from the product data array */]%%
%%[
VAR @productName SET @productName = TreatAsContent('{{experience}}')
VAR @productUrl SET @productUrl = TreatAsContent('{{url}}')
VAR @productImageUrl SET @productImageUrl = TreatAsContent('{{image}}')
]%% 

[not code] IMAGE drag and drop content block where I have put %%=v(@productImageUrl)=%% as the image url 

{{/each}}

This is working in that I get images displaying for each of the products in my data array. However, I get one extra image displaying, which I believe is the content block itself. So for example, if I have 3 products in my data array, the email renders with:

[Product 1 image]

[Product 2 image]

[Product 3 image]

[Product 3 image] --> this is product 3's image again

That last Product 3 image shouldn't display. I believe this is happening because I have the content block in the email and it therefore renders for each repeat and then once for it being there in the first place (does that make sense?).

If I use an HTML block with <img> tags instead, then it works correctly (as per the below):

%%[
  /* Set the data extension field containing the array as a variable */
  VAR @productsArray SET @productsArray = Products
]%% 

%%[/* Define the array to parse and create the data object */]%%
{{.dataobject productsData type=variable source=@productsArray}} 
  {{.data}} 
    {
      "target":"@productsArray"
    } 
  {{/data}} 
{{/dataobject}}

{{#each productsData}}    

%%[/* Set some variables from the product data array */]%%
%%[
VAR @productName SET @productName = TreatAsContent('{{experience}}')
VAR @productUrl SET @productUrl = TreatAsContent('{{url}}')
VAR @productImageUrl SET @productImageUrl = TreatAsContent('{{image}}')
]%% 

%%[/* Print the product details */]%%

<img src="%%=v(@productImageUrl)=%%" width="50px" height="50px">

{{/each}}

Is there a way to prevent the repeat of the last product's image when using drag and drop content blocks?

EDIT: Added in JSON sample below:

[
  {
    "experienceid" : 121, 
    "experience": "Product 1", 
    "image": "https://res.cloudinary.com/productimage1.jpg", 
    "url": "https://www.abc.com/product1"
  },
  {
    "experienceid" : 122, 
    "experience": "Product 2", 
    "image": "https://res.cloudinary.com/productimage2.jpg", 
    "url": "https://www.abc.com/product2"
  },
  {
    "experienceid" : 123, 
    "experience": "Product 3", 
    "image": "https://res.cloudinary.com/productimage3.jpg", 
    "url": "https://www.abc.com/product3"
  }
]
5
  • Ben, can you share a JSON sample? – Aaron Cates Feb 16 at 13:31
  • Also, does it appear that there is a carriage return at the end of the JSON in the data extension? – Aaron Cates Feb 16 at 13:39
  • @AaronCates I have added a JSON sample – Ben Feb 16 at 21:49
  • Ben, Sorry but I've not been able to replicate the behavior you're describing. Each block renders 3 imageUrls only. – Aaron Cates Feb 18 at 3:08
  • No problem. I used a separate content block and then used GetContentBlockById and that works – Ben 7 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.