Created
July 23, 2011 22:29
-
-
Save doup/1101956 to your computer and use it in GitHub Desktop.
Example twig paginator in Symfony2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
Search Page paginator | |
--------------------- | |
app.request.query.all returns the GET parameters, we merge them with the "params" so that we don't lose the search GET params. | |
#} | |
{% include "paginator.html.twig" with {"page": 2, "pages": 10, "route": 'controller_index', "params": {"some": "params"}} %} | |
{# paginator.html.twig #} | |
<ul class="paginator"> | |
{% for i in 1..pages %} | |
<li class="{{ (i == page) ? 'current':''}} {{ loop.first ? 'first':'' }} {{ loop.last ? 'last':'' }}"> | |
{% if i == page %} | |
{{ page }} | |
{% else %} | |
<a href="{{ path(route, params|merge(app.request.query.all)|merge({'page': i})) }}">{{ i }}</a> | |
{% endif %} | |
</li> | |
{% endfor %} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment