Expand my Community achievements bar.

SOLVED

How to set variable value in Personalization Block using Embedded JavaScript (EJS)

Avatar

Level 1

Hi,

I am working on an email templating project in which I am trying to set a variable value in Personalization Block through Embedded JavaScript(EJS) Syntax.

The issue I am facing is that I'm unable to set the value in variable. Upon rendering it is simply displaying the text. For example: 

 

Code: 

 

 

 

<% var subject = %> <?= cms.subject ?>

 

 

 

 

Rendered in Personalization Block

1.PNG


Scenario:
I am working with Contentful(Headless CMS) which is linked with Adobe Campaign. I upload the HTML with Embedded JavaScript (EJS) template on Contentful and from there I push the code to Adobe Campaign Personalization Block. Once the code is rendered so it looks something like the above screenshot as shown.

I tried using the below code but it doesn't work

<% var subject = "<?= cms.subject ?>" %>

because it throws an error, when I upload the document on Contentful, by stating that it cannot find the closing tag "<?". So somehow I need to achieve this by concatenation or I would say by extracting input element attribute value like below, so I can easily assign the value in variable.

 

 

 

 

<input id="emailInput" value="<?= cms.subject ?>" type="hidden" ></input>

 

 

 

 

Can anyone help to set this value ?

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 1

I was able to resolve it by converting the constructs into HTML Entities. For example:

<% var subject = "<?= cms.subject ?>" %>

is equal to:

&lt;% var subject ="<?= cms.subject ?>"; %&gt;

 
By converting the syntax, I was able to pass the syntax through Contentful and then syntax was successfully rendered in Adobe. 

View solution in original post

3 Replies

Avatar

Community Advisor

Hello @ali_muhammad93 

try this : 

<% var subject = cms.subject %>

 

Br,

Amine

Avatar

Level 1

Hi @Amine_Abedour,

The "cms.subject" can only work with EJS syntax Like: 

<?= cms.subject ?>

only then it can print the output otherwise in Personalized Block it will give an error that "cms" is undefined. 

Avatar

Correct answer by
Level 1

I was able to resolve it by converting the constructs into HTML Entities. For example:

<% var subject = "<?= cms.subject ?>" %>

is equal to:

&lt;% var subject ="<?= cms.subject ?>"; %&gt;

 
By converting the syntax, I was able to pass the syntax through Contentful and then syntax was successfully rendered in Adobe.