0

I have the following code :

{% if sr %}
      {% for lap in filter.qs|slice:":20" %}
        <tr >
          <td class="col-sm-3">
              <div >
                    <div class="product-image-wrapper">
                        <div class="single-products">
                            <div class="productinfo text-center">
                                <img src="{{ lap.product_image }}" alt=""  />
                            </div>
                        </div>
                    </div>
             </div>
          </td>
           <td class="col-sm-3">

             <h5><a href="{{ lap.product_url }}">{{ lap.product_name }}</a> </h5>
              <br>
{#                      <h5 class="btn btn-outline-secondary"><a href="{{ k.product_url }}" >See Details</a> </h5>#}
             <a href="{{ lap.product_url }}" class="btn btn-secondary" role="button" aria-pressed="true"

             style="background-color: #3e4e6f; color: white">See Details</a>

          </td>

          <td class="col-sm-3">{{ lap.product_price }} &#2547;</td>
          <td class="col-sm-3">{{ lap.vendor_name }}</td>

        </tr>
      {% empty %}
        <tr>
          <td colspan="5">No data</td>
        </tr>
      {% endfor %}
{% endif %}

Where I want to pass the parameter sr from if loop to the next for loop along the existing filter.qs|slice:":20" parameter in the following part.

{% if sr %}
      {% for lap in filter.qs|slice:":20" %}

How can I pass it? Please help.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
sksoumik
  • 845
  • 1
  • 9
  • 23
  • `if` is not a loop. Just write `sr` wherever you want to use it inside the for loop. – Vaibhav Vishal Mar 20 '19 at 09:51
  • Possible duplicate of [Django template, send two arguments to template tag?](https://stackoverflow.com/questions/39021159/django-template-send-two-arguments-to-template-tag) – webbyfox Mar 20 '19 at 09:52
  • @VaibhavVishal doesn't work. Can you please write a sample way to do this? – sksoumik Mar 20 '19 at 09:58
  • What do you mean "pass the parameter sr from if loop to the next for loop" ??? Sorry but I just cannot make sense of this question... – bruno desthuilliers Mar 20 '19 at 10:06
  • The sr variable belongs to a search form and the filter. qs belongs to a filter. I want aggregate both of these two variables in the for loop. – sksoumik Mar 20 '19 at 10:21
  • I think you want something like `for lap in (filter.qs|slice:":20" + sr)`. You should do something like this your view method. But it's still unclear what exactly you want. Maybe you can provide some sample of what exactly is in these two variables – Vaibhav Vishal Mar 20 '19 at 10:24

0 Answers0