Paginate posts (#9)

Squashed commit of the following:
Author: matis.mazingue <matis.mazingue@etu.uca.fr>
Author: clfreville2 <clement.freville2@etu.uca.fr>
This commit is contained in:
2024-06-10 19:20:15 +02:00
parent 9640b3c102
commit b4a1ae592f
4 changed files with 75 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
{% set route = app.request.attributes.get('_route') %}
<nav>
<ul class="pagination">
<li class="page-item {{ page < 2 ? 'disabled' }}">
<a class="page-link" href="{{ path(route, {'page': page - 1}) }}">Previous</a>
</li>
{% if page > 1 %}
<li class="page-item">
<a class="page-link" href="{{ path(route, {'page': page - 1}) }}">{{ page - 1 }}</a>
</li>
{% endif %}
<li class="page-item active" aria-current="page">
<a class="page-link">{{ page }}</a>
</li>
{% if page + 1 <= maxPage %}
<li class="page-item">
<a class="page-link" href="{{ path(route, {'page': page + 1}) }}">{{ page + 1 }}</a>
</li>
{% endif %}
<li class="page-item {{ page + 1 > maxPage ? 'disabled' }}">
<a class="page-link" href="{{ path(route, {'page': page + 1}) }}">Next</a>
</li>
</ul>
</nav>

View File

@@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}
{% block title %}Posts{% endblock %}
{% block body %}
{% for post in posts.iterator %}
<div class="card" style="width: 42rem; margin: 20px 0 50px 100px;">
<div class="card-body">
<h5 class="card-title">{{ post.species ? post.species.vernacularName : 'Post' }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ post.foundDate | date("d/m/Y \\à H \\h") }}</h6>
<p class="card-subtitle mb-2 text-muted">{{ post.latitude }}, {{ post.longitude }}, {{ post.altitude }}m</p>
<p class="card-text">{{ post.commentary }}</p>
</div>
<div class="card-footer">
28 ❤️
128 💬
</div>
</div>
{% endfor %}
{% include '_pagination.html.twig' %}
{% endblock %}