0

I have set up a GTL and AMP script that looks at my attributes where i passed in a Json string (array). This is the string:

`[{"MiddleName":"der","LastName":"Test"},{"MiddleName":"van der","LastName":"Test2"}]`

The output is as expected. If there is only one name the output gaves me one name and when the field has the two names he gave me two names (and so on) However, if there is more then one name the names has to be seperated by the word AND. So in my email i will get: der Test and van der Test2. How can I achieve this? If i put the word AND in my loop he always give me that word even if there is one name in place. Is there some script that i can use that checks if there is more then one name and only then print out the word AND?

Hope that the quenstion is clear to understand?

THanks a lot, Martijn

1
  • Anybody who can help me?
    – Martijn e
    Jan 9, 2019 at 8:36

1 Answer 1

0

I know this is far less than ideal, but if you have a say over the JSON itself, you could put some sort of boolean end-of-recordset attribute in your records, then throw a GTL "if" statement on your output...

`[{"MiddleName":"der","LastName":"Test","EndOfRecordSet":0},{"MiddleName":"van der","LastName":"Test2","EndOfRecordSet":1}]`

then in GTL...

{{#if EndOfRecordSet==0}} AND {{/if}}

I hope someone can provide a more elegant solution though. It seems like you should be able to use the Handlebars approach of [object].length and index referencing, but I'm not sure if GTL properly supports that. I haven't been able to make it work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .