I am trying to pass a variable into a GTL datasource to get a set of nested values from a JSON so they can be used to dynamically theme an HTML module. In the below example I am able to get the values when I set:
{"target": "themes.hero"}
However, my attempts to use a variable have failed (Email compiler spits out blanks. Can anyone help please? Why does the first target allow an AMPScript variable but not the second?
%%[
var @global_themes, @theme
set @global_themes = '{
"hero": {
"backgroundColour": "#96151D",
"headerColour": "#FFFFFF",
"copyColour": "#FFFFFF",
"linkColour": "#FFFFFF"
},
"themeOne": {
"backgroundColour": "#FFFFFF",
"headerColour": "#1A1A1A",
"copyColour": "#666666",
"linkColour": "#96151D"
}
}'
set @theme = "hero"
]%%
{{.datasource themes type=variable}}
{{.data}}
{"target": "@global_themes"}
{{/data}}
{{.datasource themes type=nested}}
{{.data}}
{"target": "themes.@theme"}
{{/data}}
backgroundColour: {{backgroundColour}}<br>
headerColour: {{headerColour}}<br>
copyColour: {{copyColour}}<br>
linkColour: {{linkColour}}<br>
{{/datasource}}
{{/datasource}}