Skip to content

Commit

Permalink
move code before and after recipe "for" loop to separate files #88
Browse files Browse the repository at this point in the history
Keeping in line with the principle of DRY, the same code can be used on 2 pages (and on future Filter or Favourites pages as well)
  • Loading branch information
blahosyl committed Jun 17, 2024
1 parent a98882e commit d756a84
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 53 deletions.
31 changes: 6 additions & 25 deletions collection/templates/collection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,13 @@

{% block content %}

<div class="container-fluid">
<div class="row">
{% include "./snippets/before_recipe_list.html" %}

<!-- Blog Entries Column -->
<div class="col-12 mt-3 left">
<div class="row">
{% for recipe in recipe_list %}
{% include "./snippets/recipe_list.html" %}
{% endfor %}
{% for recipe in recipe_list %}
{% include "./snippets/recipe_list.html" %}
{% endfor %}

{% include "./snippets/after_recipe_list.html" %}

</div>
</div>
</div>
{% if is_paginated %}
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}" class="page-link"> &laquo; PREV</a></li>
{% endif %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}" class="page-link"> NEXT &raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>

<!-- index.html content ends here -->
{% endblock %}
38 changes: 10 additions & 28 deletions collection/templates/collection/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,18 @@ <h1>Search Results for "{{ query }}"</h1>

{% if object_list%}

<div class="container-fluid">
<div class="row">

<!-- Blog Entries Column -->
<div class="col-12 mt-3 left">
<div class="row">
{% for recipe in object_list %}
<!-- based on https://learndjango.com/tutorials/django-search-tutorial -->
{% include "./snippets/recipe_list.html" %}
{% endfor %}

</div>
</div>
</div>
{% if is_paginated %}
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}" class="page-link"> &laquo; PREV</a></li>
{% endif %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}" class="page-link"> NEXT &raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>
{% include "./snippets/before_recipe_list.html" %}

{% for recipe in object_list %}
<!-- for loop based on https://learndjango.com/tutorials/django-search-tutorial -->
{% include "./snippets/recipe_list.html" %}
{% endfor %}

{% include "./snippets/after_recipe_list.html" %}


{% else %}
<p>There were no matches for your search.</p>
<p>There were no matches for your search.</p>
{% endif %}


Expand Down
17 changes: 17 additions & 0 deletions collection/templates/collection/snippets/after_recipe_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- code that comes after the for loop creating the list of recipes on index.html and search_results.html -->
</div>
</div>
</div>
{% if is_paginated %}
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}" class="page-link"> &laquo; PREV</a></li>
{% endif %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}" class="page-link"> NEXT &raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- code that comes before the for loop creating the list of recipes on index.html and search_results.html -->

<div class="container-fluid">
<div class="row">

<!-- Blog Entries Column -->
<div class="col-12 mt-3 left">
<div class="row">

0 comments on commit d756a84

Please sign in to comment.