Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

dynamic delivery

Avatar

Level 1

hi,

i was given a task to create a dynamic delivery but not to use the personalization block.

the task was to change certain content in a pre defined template based on gender.

help me out.

thank you in advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @him2 ,

In your predefined template > source tab, you can copy paste the below script and alter it with the requirement content

<HTML>
<HEAD> 
</HEAD> 
<BODY>
<P>Hi,</P>
<P>Gender: <% if ( recipient.gender == 1 ) { %>content for Male<% } if ( recipient.gender == 2 ) { %> content for Female<% } %></P>
</BODY>
</HTML>

By using the above script, Preview/Result:

Preview for Male Recipient:

ParthaSarathy_0-1681714327844.png

 

Preview for Female Recipient:

ParthaSarathy_1-1681714386523.png

And additionally you can use 'else' for default recipients or can add recipient.gender == 0 for defining content for gender as 'none specified'

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @him2 ,

In your predefined template > source tab, you can copy paste the below script and alter it with the requirement content

<HTML>
<HEAD> 
</HEAD> 
<BODY>
<P>Hi,</P>
<P>Gender: <% if ( recipient.gender == 1 ) { %>content for Male<% } if ( recipient.gender == 2 ) { %> content for Female<% } %></P>
</BODY>
</HTML>

By using the above script, Preview/Result:

Preview for Male Recipient:

ParthaSarathy_0-1681714327844.png

 

Preview for Female Recipient:

ParthaSarathy_1-1681714386523.png

And additionally you can use 'else' for default recipients or can add recipient.gender == 0 for defining content for gender as 'none specified'

Avatar

Employee Advisor

Hi @him2,

If you cannot use a personalization block, one way to achieve dynamic content based on gender in a pre-defined template is to use conditional statements. You can use an if/else statement to check the gender of the recipient and display different content based on the result.

Here's how you can achieve using HTML and Javascript&colon;

<div id="delivery-template">

  <h1>Thank you for your order, [name]!</h1>

  <p>Your [item] will be delivered to:</p>

  <p>[address]</p>

  <script>

    var gender = 'male'; // or 'female'

    var name = 'John';

    if (gender === 'male') {

      document.write('<p>Dear Mr. ' + name + ',</p>');

    } else {

      document.write('<p>Dear Ms. ' + name + ',</p>');

    }

  </script>

</div>

You can customize this example to fit your specific needs, including adding more conditional statements for other gender-specific content.

Avatar

Administrator

Hi @him2,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!



Sukrity Wadhwa