Expand my Community achievements bar.

Dynamic variables in PQL

Avatar

Level 2

We have content in JSON for multiple languages (only two in the example but in reality there would be more).

Content:

{% let content =
{"en":{
"heading":"Heading English",
"copy":"Copy English",
"cta":"Button English",
},
"no":{
"heading":"Heading Norwegian",
"copy":"Copy Norwegian",
"cta":"Button Norwegian",
}}%}
 
We'd wish to use PQL to deliver the content in right language, based on profile's language. In order for us to create the logic we would need to something like below (for English and Norwegian). In the html content we would then call these img, heading, copy etc. variables.
 
Logic:
{% let language = profile._mycompany.preferredLanguageCode %}

{% let img = content.en.img %}
{% let heading = content.en.heading %}
{% let copy = content.en.copy %}
{% let cta = content.en.cta %}
{% let link = content.en.link %}

{%#if language = "no" %}
{% let img = content.no.img %}
{% let heading = content.no.heading %}
{% let copy = content.no.copy %}
{% let cta = content.no.cta %}
{% let link = content.no.link %}
{%/if%}
 
If we have more languages the if/else logic becomes very long. Is there a way to create dynamic variables in PQL? Whatever the syntax would be, looking for something like this:
{% let heading = concat('content.', @Language, '.heading') %}
1 Reply

Avatar

Community Advisor

@MauriP 

 

I will suggest to use fragments for each language and call the fragments in the email content. The other approach in case you want to be able to see the reporting per language is to leverage conditional content.

 

DavidKangni_0-1742913402439.png

 

Thanks,

David



David Kangni