1

I'm new in using GTL, I want to know if someone has an example of a GTL Basic Personalization.

I have this JSON :{ “First Name” : “Angela”, “Last Name” : “Cruz”, “City” : “Chicago”} and this html:

<html> <body> <h1>Hello {{First Name}} {{Last Name}} from {{City}}!<h1> </body> </html>

I have already created the data extension and email.

My Question is how do I link my JSON to the email so when I preview the email it fills the data variables within my email preview and test?

1
  • Please note that in your JSON, you are not using the " char, you are using the special characters and which can cause syntax or other errors. Commented Mar 1, 2019 at 13:56

2 Answers 2

0

@thechrishaddad was close, but not quite with his answer.

If you don't want to push the GTL variables to AMPscript, you can follow the example (with slight modification by me) from the documentation:

%%[ var @Json set @Json = ' {"emailaddress":"[email protected]","Region":"East","State":"North Carolina","City":"Charlotte"}' ]%%
{{.dataobject JsonVar type=variable source=@Json maxrows=20}}
     {{.data}} 
          {"target":"@Json"} 
     {{/data}}
{{/dataobject}}
{{#jsonvar}}
Email Address: {{emailaddress}}<br>
Region: {{region}}<br>
State: {{state}}<br>
       City: {{JSONVar.City}}
{{/jsonvar}}

This will output your GTL data as required.

Now, if you do want to push the GTL variables into AMPscript variables, I have updated @thechrishaddad's code to display a working version with correct syntax:

%%[
  SET @bar = '{ "First Name" : "Angela", "Last Name" : "Cruz", "City" : "Chicago"}' 
]%%
{{.datasource details type=variable source=@bar}}
{{.data}}
  {"target":"@bar"}
{{/data}}
%%[
  SET @FirstName = TreatAsContent('{{[First Name]}}')
  SET @LastName = TreatAsContent('{{[Last Name]}}')
  SET @City = TreatAsContent('{{City}}')
]%%
Hello %%=V(@FirstName)=%% %%=V(@LastName)=%% from %%=V(@City)=%%!

{{/datasource}}

Notes on changes:

  1. The {{/datasource}} needs to below the output if you want to run this similar to a FOR loop and output multiple rows/objects in your JSON. (As there is only 1 row/object on this sample, it is not required, but wanted to note for any future needs.)
  2. All GTL variables with whitespace in their names requires [ ] around them.
  3. In order for AMPscript to recognize GTL variables, you need to wrap them in a TreatAsContent() function.
2

You need to assign your JSON data within your field to a variable first, Once you have done that, you then need to target that variable within your GTL like so to obtain each value from each property and output the variables within your HTML code like so:

I have not tested this code and it is an example for you to reference, please adjust to suit your environment.

%%[
  SET @bar = foo /* JSON Data Field in your DE */ 
]%%
{{.datasource details type=variable source=@bar}}
{{.data}}
  {"target":"@bar"}
{{/data}}
%%[
  SET @FirstName = {{First Name}}
  SET @LastName = {{Last Name}}
  SET @City = {{City}}
]%%
{{/datasource}}

<html>
 <body>
    <h1>Hello %%=V(@FirstName)=%% %%=V(@LastName)=%% from %%=V(@City)=%%!<h1>
 </body>
</html>
0

You must log in to answer this question.

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