CMS Development

salman
Member

Can we store custom variables such as {email.greetings} to can be used universally across templates?

SOLVE

I would like to use variables (large strings, etc) that I use across campaigns and workflows. I have learned here, that you can set variables using commands like:

{% set string_var = "This is a string value stored in a variable" %}
{{ string_var}}
 
However, the page does not explain where I store them. Ideally, I am expecting like a notes file where all the set variables have been stored, and can be called on any email or landing page.
 
I understand that these can be set in any given template itself, but i need to be able to call them  universally in any other template as well.
 
How can I achieve this? Thanks in advance.
1 Accepted solution
ndwilliams3
Solution
Key Advisor

Can we store custom variables such as {email.greetings} to can be used universally across templates?

SOLVE

You could add an HTML module to a page or email template and make it a gobal module. Add your variables there. You would have to add the module to any template you want to use those variables.

 

Another option is the create a coded file to store those variables and call the file in your templates using the import function.

 

In the coded file, define your variables.

{% set string_var1 = "This is a string value 1 stored in a variable" %}

 

In the template, import your variables

{% import 'custom/page/hubl/variables.html' as variables %}

 

Use the variable in your template
{{variables.string_var1}}

View solution in original post

2 Replies 2
ndwilliams3
Solution
Key Advisor

Can we store custom variables such as {email.greetings} to can be used universally across templates?

SOLVE

You could add an HTML module to a page or email template and make it a gobal module. Add your variables there. You would have to add the module to any template you want to use those variables.

 

Another option is the create a coded file to store those variables and call the file in your templates using the import function.

 

In the coded file, define your variables.

{% set string_var1 = "This is a string value 1 stored in a variable" %}

 

In the template, import your variables

{% import 'custom/page/hubl/variables.html' as variables %}

 

Use the variable in your template
{{variables.string_var1}}

aay
Participant

Can we store custom variables such as {email.greetings} to can be used universally across templates?

SOLVE

How did you code the separate file that is called upon?

0 Upvotes