Yusuf
Yusuf

Reputation: 3443

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>

Upvotes: 1

Views: 863

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476557

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

Upvotes: 2

Related Questions