I have an email that can have multiple subject lines. This is based on the incoming data. For this, 1 content block is loaded containing all the different subject lines. The correct subject line is shown via a large IF ELSE statement.

Now some subject lines contain a variable. And to make it even more complex, this variable differs based on whether the field is filled or not. This is now working fine and looks like this:

set @klantnaam = AttributeValue('klantnaam')
set @bedrijfsnaam = AttributeValue('bedrijfsnaam')

IF @bedrijfsnaam != '' then
set @subjectKlant = concat('',@bedrijfsnaam,'')
set @subjectKlant = concat('',@klantnaam,'')

if @identifier_moment == 'XXX' then      
  set @subjectline = concat('We hebben je pakket van ',@subjectKlant,' ontvangen')

elseif @identifier_moment == 'XXX' then
  set @subjectline = concat('We hebben je pakket van ',@subjectKlant,' ontvangen')

  set @subjectline = 'Volg je pakket'

Now we have to make a change and the data for the subjectKlant variable is no longer available via a attribute field but is comming into a JSON. I build the following:

Set @adressen = [adressen] 

{{.datasource adressenVar type=variable source=@adressen maxrows=1}}
var @subjectKlant
set @subjectKlant = TreatAsContent('{{bedrijfsnaam}}')

And this is the JSON structure:

    "kind": "1",
    "persoonsnaam": "Test1",
    "bedrijfsnaam": "Test1 BV"
}, {
    "kind": "2",
    "persoonsnaam": "Test2",
    "bedrijfsnaam": "Test2 BV"

Basically this works. However, I face some difficulties that I can not solve at the moment. Hopefully some of you will know the answer. I have two questions:

  1. I have to check weither bedrijfsnaam is empty or not in the JSON. If not empty then show the content of that field, if the field IS empty then show the content of field persoonsnaam (like I build with AMPscript). How can I achieve this?
  2. How can I target a specific object within the JSON array? So suppose I want to target the fields that is under kind: 2?
  • Aperently this work. I think it has something to do with the maxrows: {{.datasource adressenVar type=variable source=@ adressen maxrows=3}} {{.data}} {"target":"@ adressen"} {{/data}} {{#if adressoort=="1"}} {{#if bedrijfsnaam!=""}} %%[ var @ subjectKlant set @ subjectKlant = TreatAsContent('{{bedrijfsnaam}}') ]%% {{.else}} %%[ var @ subjectKlant set @ subjectKlant = TreatAsContent('{{persoonsnaam}}') ]%% {{/if}} {{/if}} {{/datasource}}
    – Martijn e
    Commented Jan 9, 2023 at 12:32

1 Answer 1


I'm not familiar with Guide Template Language but upon checking on some official documentations here are two tags you can leverage:

  1. if else tag to handle conditions
  2. each tag to loop through an array and find the object you need

However, I'll have to agree with the answer in this post that you should probably discard GTL altogether and use SSJS instead. Logic and codes would be more robust that way in my opinion.

  • Yes I tried the if else function but I can't set values to use elsewhere. So when I do something like this it doesn't work: {{#if adressoort=="1"}} {{#if bedrijfsnaam!=""}} set @ subjectKlant = TreatAsContent('{{bedrijfsnaam}}') {{.else}} set @ subjectKlant2 = TreatAsContent('{{persoonsnaam}}') {{/if}} {{/if}} %%=v(@subjectKlant)=%%<br/> %%=v(@subjectKlant2)=%% However, when I do something like this than it works: {{#if adressoort=="1"}} {{#if bedrijfsnaam!=""}} {{bedrijfsnaam}} {{.else}} {{persoonsnaam}} {{/if}} {{/if}}
    – Martijn e
    Commented Jan 9, 2023 at 8:49
  • Not sure if this snippet you added is the literal copy you used, but within the if/else in your GTL where you're assigning the value to subjectKlant, you'd still need to add open and close brackets ... %%[ set @ subjectKlant = TreatAsContent('{{bedrijfsnaam}}') ]%% Commented Jan 23, 2023 at 18:01

You must log in to answer this question.

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