标签:
{% macro paging(page, max, url, num = 5) %}
{% if page < 1 %}{% set page = 1 %}{% endif %}
{% if page > max %}{% set page = max %}{% endif %}
{% set jianju = (num / 2)|round %}
<nav class="pull-right">
<ul class="pagination">
<li {% if page == 1 %}class="disabled"{% endif %}><a {% if page != 1 %}href="{{ url }}1"{% endif %} aria-label="Previous"><span aria-hidden="true">首页</span></a></li>
<li {% if page < 2 %}class="disabled"{% endif %}><a {% if page >= 2 %}href="{{ url }}{{ page - 1 }}"{% endif %} aria-label="Previous"><span aria-hidden="true">上页</span></a></li>
{% if max <= num %}
{% for ii in 1..max %}
<li {% if page == ii %}class="active"{% endif %}><a href="{{ url }}{{ ii }}">{{ ii }}</a></li>
{% endfor %}
{% endif %}
{% if max > num and page <= num and page < jianju %}
{% for ll in 1..num %}
<li {% if page == ll %}class="active"{% endif %}><a href="{{ url }}{{ ll }}">{{ ll }}</a></li>
{% endfor %}
{% endif %}
{% if max > num and (page - jianju) >= 0 and (page + jianju) <= max %}
{% for jj in (page - jianju + 1)..(page + jianju - 1) %}
<li {% if page == jj %}class="active"{% endif %}><a href="{{ url }}{{ jj }}">{{ jj }}</a></li>
{% endfor %}
{% endif %}
{% if max > num and page > (max - jianju) %}
{% for kk in (max - num + 1)..max %}
<li {% if page == kk %}class="active"{% endif %}><a href="{{ url }}{{ kk }}">{{ kk }}</a></li>
{% endfor %}
{% endif %}
<li {% if page+1 > max %}class="disabled"{% endif %}><a {% if page+1 <= max %}href="{{ url }}{{ page + 1 }}"{% endif %} aria-label="Next"><span aria-hidden="true">下页</span></a></li>
<li {% if page == max %}class="disabled"{% endif %}><a {% if page != max %}href="{{ url }}{{ max }}"{% endif %} aria-label="Previous"><span aria-hidden="true">末页</span></a></li>
</ul>
</nav>
{% endmacro %}
TWIG 分页宏(基于 bootstrap)
标签:
原文地址:http://www.cnblogs.com/fairyin/p/4462453.html