From 2a6c1f050d6f7281a4250e8e127e86408a2a3369 Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 11 Aug 2024 15:11:51 +0200 Subject: [PATCH] Create a paginate_alpine macro --- core/templates/core/macros.jinja | 40 +++++++++++++++++++++++++ pedagogy/templates/pedagogy/guide.jinja | 25 ++-------------- sas/templates/sas/album.jinja | 24 ++------------- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/core/templates/core/macros.jinja b/core/templates/core/macros.jinja index 2344de37..11014a64 100644 --- a/core/templates/core/macros.jinja +++ b/core/templates/core/macros.jinja @@ -116,6 +116,46 @@ {% endif %} {% endmacro %} +{% macro paginate_alpine(page, nb_pages) %} + {# Add pagination buttons for ajax based content with alpine + + Notes: + This can only be used in the scope of your alpine datastore + + Notes: + You might need to listen to the "popstate" event in your code + to update the current page you are on when the user goes back in + it's browser history with the back arrow + + Parameters: + page (str): name of the alpine page variable in your datastore + nb_page (str): call to a javascript function or variable returning + the maximum number of pages to paginate + #} + +{% endmacro %} + {% macro paginate(page_obj, paginator, js_action) %} {% set js = js_action|default('') %} {% if page_obj.has_previous() or page_obj.has_next() %} diff --git a/pedagogy/templates/pedagogy/guide.jinja b/pedagogy/templates/pedagogy/guide.jinja index 639ee0ca..e2ab4d22 100644 --- a/pedagogy/templates/pedagogy/guide.jinja +++ b/pedagogy/templates/pedagogy/guide.jinja @@ -1,4 +1,5 @@ {% extends "core/base.jinja" %} +{% from 'core/macros.jinja' import paginate_alpine %} {% block title %} {% trans %}UV Guide{% endtrans %} @@ -113,29 +114,7 @@ - + {{ paginate_alpine("page", "max_page()") }}