Skip to content

Instantly share code, notes, and snippets.

@doup
Created July 23, 2011 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doup/1101956 to your computer and use it in GitHub Desktop.
Save doup/1101956 to your computer and use it in GitHub Desktop.
Example twig paginator in Symfony2
{#
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