Possible to reference TargetData within an If statement | Community
Skip to main content
New Participant
July 31, 2024
Solved

Possible to reference TargetData within an If statement

  • July 31, 2024
  • 1 reply
  • 842 views

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

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 AndyHu5

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
<%} %>
<%} %>



1 reply

ccg1706
New Participant
August 1, 2024

Hi @andyhu5,

 

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

 

AndyHu5AuthorAccepted solution
New Participant
August 8, 2024

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
<%} %>
<%} %>



ccg1706
New Participant
August 8, 2024

Thanks @andyhu5 for sharing another way of doing it.

 

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