Hi everyone,
I am trying to use Dynamic Content to feed my data into variables in the email. For example, someone will donate $50 so I want to say, If user donation>0, then say, “You will be donating $50.”
Yet, I am having issues.
- Can you have more than one If statement in an email? (CP Amount is the amount they will donate)
{% if subscriber.custom_field[‘CP Amount’] > ‘0’ %}It is our understanding that you personally will be giving US${{subscriber.custom_field[‘CP Amount’] }}. {% endif %}
{% if subscriber.custom_field[‘CP Amount’] > ‘4000’ %}Please note that $4,000 of your donation is the course fee and therefore, not tax deductible in the US. {% endif %}
- Why is this statement not working? No amount shows in the email:
{% if subscriber.custom_field[‘CP Amount’] > ‘0’ %}It is our understanding that you personally will be giving US${{subscriber.custom_field[‘CP Amount’] }}. {% endif %}
Hi Elaine,
You can definitely use dynamic content like a mail merge.
What you’re trying to do is exactly what dynamic content was designed to support. Conditionals based on subscriber custom variable content displaying different content depending on the value of those fields.
I was just looking at the “Acceptance” message you were editing that has the first conditional above and when I provide values in the “preview and test” section of the message editor for each of the 3 fields you are using, I see the appropriate content being displayed.
The “Acceptance-Jan 3” email had some HTML embedded in the dynamic content that wasn’t visible but causing issues. I removed that HTML and it appears to render correctly now.
I have a message in to our engineering team about the evaluation of strings as numerics as, off the top of my head, I don’t believe that’s going to work properly as currently written.
Thank you, Tom, for your reply. Yes, it works when you send a test message, but not when you schedule a message and try to send to several subscribers at once.
Please let me know what your engineers say about point #2 above, as I think that is what you are referring to when you wrote, “evaluation of strings as numerics.”
Thanks!
Elaine,
The “Acceptance-Jan 3” email in your account has been corrected to properly use integers. Note the addition of the | int in the various number comparisons you had added. Those convert the custom fields that store text data by default back into integer values since you’re storing numeric data in those fields.
Please confirm on your end, but the logic should be working now based on what you intended.
Dear Tom,
Thank you very much for this solution. In initial testing, it worked for 2 out of 4 of the scenarios. We will test it further tomorrow when we have more time and post the results here.
We appreciate your help.
Elaine
Hi again Tom,
After testing further, I found that I could not enter a comma separator when entering the data. That is why only 2 out of 4 scenarios worked - the 2 that did not work had data where the numbers had comma separators.
So now that it is all working, (thank you!) is there a way to display the data entered for ‘CP Amount’ with a comma in the final email? Most of our data will need the comma separator for readability in the final email.
Regards,
Elaine
I need specifics of what you’re trying to do. Specific examples are helpful.
Does the data stored in the custom fields for specific subscribers have commas in it or are you trying to put commas in the final displayed number in the message?
They are two very different things programmatically and require different handling.
If you have commas in the custom field data, you’ll need to remove the commas before turning them into integers using the replace() function described in the filters section of dynamic content. Not tested, but something like this:
{% if subscriber.custom_field['CP Amount']|replace(',', '') | int > 4000 %}
If you want to add commas at display time, use something like this:
${{ subscriber.custom_field['CP Amount'] | int | format(",") }}
Thanks again, Tom.
I am trying to put commas in the final displayed number in the message. The data stored in the custom fields does not have commas.
For example, CP Amount = 10000. I would like that to display as 10,000 in the emails to the subscribers.
I tried this code, but it did not work. ${{ subscriber.custom_field[‘CP Amount’] | int | format(“,”) }} Aweber did not insert any data in any dynamic content.
Elaine