1
\$\begingroup\$

I have the following code in my Django template. It's a bit repetitive. I wonder if that's good the way I wrote it, or if you would combine these two 'if'-statements into one somehow?

{% elif discount.no_more_left %}
  <div class="modal fade" id="no-more-left-modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h3 class="modal-title">{{ discount.code }}</h3>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>{% trans "There are no more discount codes available. If you want to offer more, you can edit it and increase the available quantity." %}</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
        </div>
      </div>
    </div>
  </div>
{% elif discount.is_expired %}
  <div class="modal fade" id="expired-modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h3 class="modal-title">{{ discount.code }}</h3>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <p>{% trans "This discount code is expired. If you want to extend it, you can edit it and change the expiration date." %}</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
        </div>
      </div>
    </div>
  </div>
{% endif %}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.