Skip to main content
added the result
Source Link
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 JSONVar source=@global_themes type=variable}}
    {{.data}}
        { "target" : "@global_themes" }
    {{/data}}

    {{.datasource hero source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.hero" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}

    <br><br>

    {{.datasource themeOne source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.themeOne" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}
{{/datasource}}

Result

backgroundColour: #96151D
headerColour: #FFFFFF
copyColour: #FFFFFF
linkColour: #FFFFFF


backgroundColour: #FFFFFF
headerColour: #1A1A1A
copyColour: #666666
linkColour: #96151D
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 JSONVar source=@global_themes type=variable}}
    {{.data}}
        { "target" : "@global_themes" }
    {{/data}}

    {{.datasource hero source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.hero" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}

    <br><br>

    {{.datasource themeOne source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.themeOne" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}
{{/datasource}}

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 JSONVar source=@global_themes type=variable}}
    {{.data}}
        { "target" : "@global_themes" }
    {{/data}}

    {{.datasource hero source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.hero" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}

    <br><br>

    {{.datasource themeOne source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.themeOne" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}
{{/datasource}}

Result

backgroundColour: #96151D
headerColour: #FFFFFF
copyColour: #FFFFFF
linkColour: #FFFFFF


backgroundColour: #FFFFFF
headerColour: #1A1A1A
copyColour: #666666
linkColour: #96151D
Source Link

I managed to replicate the code and made some modifications - the end result is working.

Key changes:

  • added the source and referenced the AMPScript variable
  • removed the gtl escape OMM delimiters
  • added extra code to render the themeOne JSON object.
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 JSONVar source=@global_themes type=variable}}
    {{.data}}
        { "target" : "@global_themes" }
    {{/data}}

    {{.datasource hero source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.hero" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}

    <br><br>

    {{.datasource themeOne source=@global_themes type=nested}}

        {{.data}}
          { "target" : "JSONVar.themeOne" }
        {{/data}}

         backgroundColour: {{backgroundColour}}<br>
        headerColour: {{headerColour}}<br>
        copyColour: {{copyColour}}<br>
        linkColour: {{linkColour}}<br>
    {{/datasource}}
{{/datasource}}

Reference: GTL in cloudpages: #with