Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Bulma pagination template for version 0.6.x #473

Merged
merged 7 commits into from Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -94,6 +94,7 @@ There are a few additional pagination templates, that could be used out of the b
* `@KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig`
* `@KnpPaginator/Pagination/twitter_bootstrap_pagination.html.twig`
* `@KnpPaginator/Pagination/foundation_v5_pagination.html.twig`
* `@KnpPaginator/Pagination/bulma_pagination.html.twig`


## Usage examples:
Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/paginator_configuration.md
Expand Up @@ -20,5 +20,8 @@ knp_paginator:
There are a few additional pagination templates, that could be used out of the box in `knp_paginator.template.pagination` key:

* `@KnpPaginator/Pagination/sliding.html.twig` (by default)
* `@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig`
* `@KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig`
* `@KnpPaginator/Pagination/twitter_bootstrap_pagination.html.twig`
* `@KnpPaginator/Pagination/foundation_v5_pagination.html.twig`
* `@KnpPaginator/Pagination/bulma_pagination.html.twig`
26 changes: 26 additions & 0 deletions Resources/doc/templates.md
Expand Up @@ -153,3 +153,29 @@ Or even in Twig:
) }}
```

## Customize rendering

### Bulma

You can configure the position, the size, and make the buttons rounded or not:
- `position`: `'left'`, `'centered'`, or `'right'`. By default it's `'left'`
- `size`: `'small'`, `'medium'`, or `'large'`. By default, size is not modified
- `rounded`: `true` or `false`. By default it's `false`

In your controller:
```php
$pagination->setCustomParameters([
'position' => 'centered',
'size' => 'large',
'rounded' => true,
]);
```

or in the view:
```twig
{{ knp_pagination_render(pagination, null, {}, {
'position': 'centered',
'size': 'large'
'rounded': true,
}) }}
```
53 changes: 40 additions & 13 deletions Resources/views/Pagination/bulma_pagination.html.twig
@@ -1,41 +1,68 @@
{# bulma Sliding pagination control implementation #}

{% set position = position|default('left') %}
{% set rounded = rounded|default(false) %}
{% set size = size|default(null) %}

{% set classes = ['pagination'] %}

{% if position != 'left' %}{% set classes = classes|merge(['is-' ~ position]) %}{% endif %}
{% if rounded %}{% set classes = classes|merge(['is-rounded']) %}{% endif %}
{% if size != null %}{% set classes = classes|merge(['is-' ~ size]) %}{% endif %}

{% if pageCount > 1 %}
<nav class="pagination">
<nav class="{{ classes|join(' ') }}" role="navigation" aria-label="pagination">
{% if previous is defined %}
<a class="button" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">&lt;</a>
<a class="pagination-previous" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
{% else %}
<a class="button" disabled>&lt;</a>
<a class="pagination-previous" disabled>{{ 'label_previous'|trans({}, 'KnpPaginatorBundle') }}</a>
{% endif %}

{% if next is defined %}
<a class="button" href="{{ path(route, query|merge({(pageParameterName): next})) }}">&gt;</a>
<a class="pagination-next" href="{{ path(route, query|merge({(pageParameterName): next})) }}">{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}</a>
{% else %}
<a class="button" disabled>&gt;</a>
<a class="pagination-next" disabled>{{ 'label_next'|trans({}, 'KnpPaginatorBundle') }}</a>
{% endif %}
<ul>

<ul class="pagination-list">
<li>
<a class="button" href="{{ path(route, query|merge({(pageParameterName): first})) }}">1</a>
{% if current == first %}
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, query|merge({(pageParameterName): first})) }}">1</a>
{% else %}
<a class="pagination-link" href="{{ path(route, query|merge({(pageParameterName): first})) }}">1</a>
{% endif %}
</li>

{% if pagesInRange[0] - first >= 2 %}
<li>
<span>…</span>
<span class="pagination-ellipsis">&hellip;</span>
</li>
{% endif %}

{% for page in pagesInRange %}
{% if first != page and page != last %}
<li>
<a class="button"
href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
{% if page == current %}
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
{% else %}
<a class="pagination-link" aria-label="Goto page {{ page }}" href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
{% endif %}
</li>
{% endif %}
{% endfor %}
{% if last - pagesInRange[pagesInRange|length - 1] >= 2 %}

{% if last - pagesInRange[pagesInRange|length - 1] >= 2 %}
<li>
<span>…</span>
<span class="pagination-ellipsis">&hellip;</span>
</li>
{% endif %}

<li>
<a class="button" href="{{ path(route, query|merge({(pageParameterName): last})) }}">{{ last }}</a>
{% if current == last %}
<a class="pagination-link is-current" aria-label="Page {{ current }}" aria-current="page" href="{{ path(route, query|merge({(pageParameterName): last})) }}">{{ last }}</a>
{% else %}
<a class="pagination-link" href="{{ path(route, query|merge({(pageParameterName): last})) }}">{{ last }}</a>
{% endif %}
</li>
</ul>
</nav>
Expand Down