Solved

Can I use attributes from collection content

  • 4 June 2023
  • 2 replies
  • 53 views

I wanna create a collection with my variant content to a campain.

My collection have title and text attributes. In theses attributes I'did like use attributes of my customer. 
For example: 
title: "Hello {{customer.first_name}}, welcome!".
text: "Congratulations to subscribe our {{customer.plann_name}} plann!"

 

Has any way to make this possible?

icon

Best answer by Penny 5 June 2023, 09:12

View original

2 replies

Userlevel 4

Hi @renatto.machado

 

If there are Liquid attributes such as {{customer.first_name}} wtihin the collection data, I am afraid it is not quite possible at the moment.

To use collection data, you would run a Query Collection action within the campaign to save the collection data in a profile attribute, and within your campaign emails, you would reference them using Liquid, such as {{customer.title}} or {{customer.text}}. However, it wouldn’t be possible to have attribute references using Liquid within the attributes themselves as it would not render. 

You can read more about collections here: https://customer.io/docs/journeys/collections/

In the meantime, for instances where you often reuse a chunk of content that would be the same for different customers except for their personalised attributes such as name and plan name such as your example, one other option you could consider would be to use Snippets instead: https://customer.io/docs/journeys/snippets/

Hopefully I’ve not misunderstood your use case and this is helpful to you! 

 

I solved in different way.

After get value of collection, I put it in an attribute and after I've used "Create or Update Person" and using javascript I've update values with eval function.

This works beautiful!


 

 

The code in javascript to help another users in community:

function evalX(str) {
let pattern = /{{(.*?)}}/g;
str = str.replace(pattern, function(match) {
match = match.replace(/{{|}}/g, '');
return eval(match);
});
return str;
}

let contentVariant = customer.contentVariant;

contentVariant.title = evalX(contentVariant.title);
contentVariant.text = evalX(contentVariant.text);
contentVariant.textHtml = evalX(contentVariant.textHtml);

return contentVariant;

 

Reply