#Can we sent an array as payload while triggering through code ?

1 messages · Page 1 of 1 (latest)

loud falcon
#

and if so, how can we format it in the template in novu platform?

supple gull
#

Hi @loud falcon
Please share some sample code

loud falcon
#

like if we have an array of object
obj = {
name : "tom"
}[]

supple gull
#

payload is a type of object which can take only key value pairs

This is a valid payload:-

payload: {
attachments: [
{
name: "",
mime: ""
}
]
}

loud falcon
#

but if the this array of object "attachments" has like 3 elements, how will we show each element in our own format in novu platform?

supple gull
#

I think you can send, although attachments is reserved for internal purpose, but you can use other key

loud falcon
#

but how will I show the elements of this array in templates

fervent escarp
#

You can do {{#each}} {{name}} {{/each}} or other array related syntax in handlebars

loud falcon
#

could you elaborate these formats a bit

supple gull
elder rose
#

For example, for this case in the template

#
   payload: {
      array: [
        {
          name: 'gali',
          score: 2,
        },
        {
          name: 'david',
          score: 5,
        },
      ]
    }
loud falcon
#

@elder rose Thank you, this was really helpful

#

thanks @supple gull @fervent escarp for the response, it worked

loud falcon
#

Hey guys, one doubt, in the custom code editor also the payload data is accessed with {{}}, right?