Default value for field associated with deal

We currently send a few e-mails that use properties associated with our deals. I have a lot of default values set up for contact and company properties using Default values for email personalization in our settings.

However I can’t set default values for deals properties the same way. We use two properties to create the following header. This code is contained in a module that we use in our templates:

<div style=“max-width: 80%;”>
<a href=“{{deal.winkel_url}}”><left><img src=“{{deal.winkel_logo_url}}” alt=“Company Store Logo” width=“80%” height=“auto”></left></a>
</div>

Sometimes deal.winkel_url and deal.winkel_logo_url have no value which means that the no image is shown. I would like to use a default value when that’s the case.

How would I edit this code or the module to check if the property has a value and use a default image if the field turns out to be empty?

Hey @EvaUR, thank you for posting in our Community!

You can modify the code to include a conditional check for the presence of values in the deal.winkel_url and deal.winkel_logo_url properties. If either of these properties is empty, you can substitute it with a default image URL.

@DanielSanchez and @Anton do you have any recommendations for @EvaUR?

Thank you,

Pam

Hi @EvaUR,

as @PamCotton mentioned you can set a default value with a conditional-statement directly in your code/module.

Here’s an example:

{% unless deal.winkel_url == null %}
 {% set winkel_url = deal.winkel_url %}
{% else %}
 {% set winkel_url = "PATH_TO_FALLBACK" %}
{% endunless %}

{% unless deal.winkel_img_url == null %}
 {% set winkel_img_url = deal.winkel_img_url %}
{% else %}
 {% set winkel_img_url = "PATH_TO_FALLBACK IMG" %}
{% endunless %}
...
<a href="{{ winkel_url }}"><left><img src="{{ winkel_img_url }}">...</a>

best,

Anton

This worked like a dream, thank you!