how to conditional render html element in a Django template
I am using django server to send user email notifications, I came into a place where I need to say if this elemet doesn't exist add margin/space underneath the text
<tr style="padding:0;margin:0;" height="30">
<td width="190" style="font-family:Roboto;color:#000000;font-weight:bold">Date</td>
<td width="400" style="font-family:Roboto;color:#000000;">{{ processed_datetime|date:"d/m/Y H:i" }}</td>
<!--I want to say here if there is no other party email add this element underneath -->
{% if ! counterpart.email} <!--not sure about this line syntax -->
<tr style="padding:0;margin:0;" height="20">
<td width="190" height="20" style="font-family:Roboto;color:#000000;font-size:24px;line-height:32px;"></td>
</tr>
Solution 1:
You do this with not
, so:
{% if not counterpart.email %}
<tr style="padding:0;margin:0;" height="20">
<td width="190" height="20" style="font-family:Roboto;color:#000000;font-size:24px;line-height:32px;"></td>
</tr>
{% endif %}