Expand my Community achievements bar.

SOLVED

Possible to reference TargetData within an If statement

Avatar

Level 2

Hey, I'm very new to Campaign. I'm trying to hide a panel if the data that comes through matches a previous panel or the next panel. Essentially like this

<% if (targetData.Recent2Name == 'targetData.Recent1Name ' || targetData.Recent2Name == ' targetData.Recent3Name ') { %>
       Don't show  panel

<% } else {%>

        Show panel

<%} %>

I know the above won't work but I was wondering if there's a way to sort this so the Recent1Name and Recent3Name are referenced correctly?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 2

Thanks for the response

I ended up creating the targetData as a var

So in the end the working (rough) code was

<% if (targetData.Recent1Name != '') { %>
  Show Panel 1
<%} %>

<% if (targetData.Recent2Name != '') { %>
<% var aHotel1 = targetData.Recent1Name;
  var aHotel2 = targetData.Recent2Name;
  var aHotel3 = targetData.Recent3Name; %>

<% if (aHotel2 == aHotel1 || aHotel2 == aHotel3) { %> 
    Hide Panel 2
<% } else {%>
    Show Panel 2
<%} %>
<%} %>

<% if (targetData.Recent3Name != '') { %>
<% var aHotel1 = targetData.Recent1Name;
  var aHotel2 = targetData.Recent2Name;
  var aHotel3 = targetData.Recent3Name; %>

<% if (aHotel3 == aHotel1 || aHotel3 == aHotel2) { %> 
    Hide Panel 3
<% } else {%>
    Show Panel 3
<%} %>
<%} %>



View solution in original post

3 Replies

Avatar

Level 5

Hi @AndyHu1,

 

Try with this following examples:

 

<% if (targetData.Recent2Name == targetData.Recent1Name || targetData.Recent2Name == targetData.Recent3Name) { %>
<!-- Code to hide panel -->
<% } else { %>
<!-- Code to show panel -->
<% } %>

-1.Variable referencing: Single quotes are used for string literals , not for referencing variables.

- 2. Use comments  or script-based comments to indicate the sections for hiding or showing the panel.

 

If you want to do it with a div:

<% if (targetData.Recent2Name == targetData.Recent1Name || targetData.Recent2Name == targetData.Recent3Name) { %>
<div style="display:none;">
<!-- Panel content goes here -->
</div>
<% } else { %>
<div>
<!-- Panel content goes here -->
</div>
<% } %>

 

Remember to ensure 'targetData.Recent1Name', 'targetData.Recent2Name', 'targetData.Recent3Name' are available and correctly populated in the context where you are using this script.

 

Hope this suits. 

 

Kind regards, 

Celia

 

Avatar

Correct answer by
Level 2

Thanks for the response

I ended up creating the targetData as a var

So in the end the working (rough) code was

<% if (targetData.Recent1Name != '') { %>
  Show Panel 1
<%} %>

<% if (targetData.Recent2Name != '') { %>
<% var aHotel1 = targetData.Recent1Name;
  var aHotel2 = targetData.Recent2Name;
  var aHotel3 = targetData.Recent3Name; %>

<% if (aHotel2 == aHotel1 || aHotel2 == aHotel3) { %> 
    Hide Panel 2
<% } else {%>
    Show Panel 2
<%} %>
<%} %>

<% if (targetData.Recent3Name != '') { %>
<% var aHotel1 = targetData.Recent1Name;
  var aHotel2 = targetData.Recent2Name;
  var aHotel3 = targetData.Recent3Name; %>

<% if (aHotel3 == aHotel1 || aHotel3 == aHotel2) { %> 
    Hide Panel 3
<% } else {%>
    Show Panel 3
<%} %>
<%} %>



Avatar

Level 5

Thanks @AndyHu1 for sharing another way of doing it.

 

It totally, makes sense to create targetData as a var.