craphunter
craphunter

Reputation: 981

knp paginator php template

I use KnpPaginatorBundle. Usually I use php-templates in symfony2.3. Is there a way to use php-templates for pagination for the KnpPaginatorBundle? I can't find any tutorial or any docs.

Thanks.

Update How to render this in the php template?

{# total items count #}
<div class="count">
    {{ pagination.getTotalItemCount }}
</div>
<table>
<tr>
{# sorting of properties based on query components #}
    <th>{{ knp_pagination_sortable(pagination, 'Id', 'a.id') }}</th>
    <th{% if pagination.isSorted('a.Title') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'Title', 'a.title') }}</th>
</tr>

{# table body #}
{% for article in pagination %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
    <td>{{ article.id }}</td>

</tr>
{% endfor %}
</table>
{# display navigation #}
<div class="navigation">
    {{ knp_pagination_render(pagination) }}
</div>

Upvotes: 1

Views: 4511

Answers (3)

Also, you are can try template way:

{{ knp_pagination_render(content, 'MyBundle:ContentNew/Pagination:sliding.html.twig') }}

Upvotes: 0

pazulx
pazulx

Reputation: 2379

PHP version of pagination template:

<?php #total items count ?>
<div class="count">
    <?php echo $pagination->getTotalItemCount(); ?>
</div>
<table>
<tr>
<?php # sorting of properties based on query components  ?>
    <th <?php echo $view['knp_pagination']->sortable($pagination, 'Id', 'a.id') ?></th>
    <th<?php if ($pagination->isSorted('a.Title')){echo ' class="sorted"';}?>><?php echo $view['knp_pagination']->sortable($pagination, 'Title', 'a.title') ?></th>
</tr>

<?php # table body  ?>
<?php foreach ($pagination as $key => $article): ?>
<tr <?php if ($key %2 == 0){echo 'class="color"';}?>>
    <td><?php echo $article->getId() ?></td>

</tr>
<?php endforeach; ?>
</table>
<?php # display navigation  ?>
<div class="navigation">
    <?php echo $view['knp_pagination']->render($pagination) ?>
</div>

Upvotes: 2

VisioN
VisioN

Reputation: 145408

Yes, there is a way either in config:

knp_paginator.template.pagination: MyBundle:Pagination:pagination.html.php

or directly in controller:

$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate($target, $page);
$pagination->setTemplate('MyBundle:Pagination:pagination.html.php');

DOCS: https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/templates.md

Upvotes: 2

Related Questions