Dynamic variables in PQL | Community
Skip to main content
Level 2
March 25, 2025
Solved

Dynamic variables in PQL

  • March 25, 2025
  • 1 reply
  • 360 views

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.', @2199879, '.heading') %}
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by DavidKangni

@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.

 

 

Thanks,

David

1 reply

DavidKangni
Community Advisor
DavidKangniCommunity AdvisorAccepted solution
Community Advisor
March 25, 2025

@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.

 

 

Thanks,

David

David Kangni