How do I exclude null values on a form email notification with a custom layout?

Sherri Guthrie asked on September 25, 2015 17:49

I have an email notification with a custom layout. The user has the option of entering several rows on the form. I have two radio buttons that are displaying the first option by default. If the user doesn't fill out a row, I don't want to display the default data in the email. This is the code I am using for the radio buttons. {%if (CA2 == true) {"CA"} else{"CS"}#%} --> This displays CA

I want to check the other text fields on the same row to see if the value is null. If so, don't display the above field. So, I want to wrap the above code in a null check. I have tried, CADate <> "", CADate != "", notisempty etc. Any ideas?

Correct Answer

Maarten van den Hooven answered on September 28, 2015 14:43

Hello Sherri, strange, so there is a difference with my tested situation. This is what I did:

  1. I work in Kentico v8.2 (but I don't think that is the problem)
  2. Added an field with the name : CADate
  3. Data Type : Boolean
  4. Added an field with the name : CA2
  5. Data Type : Boolean and Form control : Radio buttons
  6. Options : List of options and the options are: true;True false;False
  7. In my email notification I use an custom layout and added in the source this macro : {% CADate == null ? "" : (CA2 ? "CA" : "CS") %}

And this works for me, so hopefully you can now see what is the difference with your configuration. Good luck!

0 votesVote for this answer Unmark Correct answer

Recent Answers


Maarten van den Hooven answered on September 25, 2015 19:15 (last edited on September 25, 2015 19:20)

Hi sherri,

You can try one of these two options:

{% CADate.ToString() == "" ? "empty" : "not empty" #%}

or

{% CADate == null ? "empty" : "not empty" %} 

Good luck!

If this answer helped you, please vote for my answer :-)

0 votesVote for this answer Mark as a Correct answer

Sherri Guthrie answered on September 25, 2015 21:54

I tried the 2nd option and it works but I am looking to nest them. I can't get that to work. I tried this:

{% CADate == null ? "": (CA2 == true ? "CA" : "CS")%}

I keep coming up with CS if CADate is not null even if CA2 is true.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 25, 2015 22:25

Hi Sherri,

I tested and this worked for me :

{% CADate == null ? ""  : (CA2 ? "CA" : "CS") %}
0 votesVote for this answer Mark as a Correct answer

Sherri Guthrie answered on September 28, 2015 13:57

Still getting CS if CA2 is true.

0 votesVote for this answer Mark as a Correct answer

Sherri Guthrie answered on September 28, 2015 15:43

I changed the way I did the options and your code worked. ~Thanks.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.