{% set skip = request.args.get('o')|parse_int if request.args.get('o') else 0 %} {% set currentCeilingOfRange = skip + props.limit if (skip + props.limit) < props.count else props.count %} {% set TOTAL_BUTTONS = 5 %} {% set OPTIONAL_BUTTONS = TOTAL_BUTTONS - 2 %} {% set MANDATORY_BUTTONS = TOTAL_BUTTONS - OPTIONAL_BUTTONS %} {% set currPageNum = ((skip + props.limit) / props.limit)|round(0, 'ceil')|int %} {% set totalPages = (props.count / props.limit)|round(0, 'ceil')|int %} {% set numBeforeCurrPage = currPageNum - 1 if ((totalPages < TOTAL_BUTTONS) or (currPageNum < TOTAL_BUTTONS)) else ((TOTAL_BUTTONS - 1) + ((TOTAL_BUTTONS) - (totalPages - currPageNum)) if (totalPages - currPageNum) < TOTAL_BUTTONS else (TOTAL_BUTTONS - 1)) %} {% set basePageNum = [currPageNum - numBeforeCurrPage - 1, 1]|max %} {% set showFirstPostsButton = basePageNum > 1 %} {% set showLastPostsButton = totalPages - currPageNum > (TOTAL_BUTTONS + ((TOTAL_BUTTONS - (currPageNum - basePageNum)) if currPageNum - basePageNum < TOTAL_BUTTONS else 0)) %} {% set optionalBeforeButtons = currPageNum - MANDATORY_BUTTONS - ((MANDATORY_BUTTONS - (totalPages - currPageNum)) if totalPages - currPageNum < MANDATORY_BUTTONS else 0) %} {% set optionalAfterButtons = currPageNum + MANDATORY_BUTTONS + ((MANDATORY_BUTTONS - (currPageNum - basePageNum)) if currPageNum - basePageNum < MANDATORY_BUTTONS else 0) %} {% macro paginator_button(content, href=none, class_name=none) %} {%if href %} {{ content }} {%else%}