3

I'm using Pagerfanta bundle with Symfony 3.3.4 and Bootstrap 3;

    "php": ">=5.5.9",
    "components/jquery": "^3.2",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/orm": "^2.5",
    "incenteev/composer-parameter-handler": "^2.0",
    "kriswallsmith/assetic": "^1.4",
    "oyejorge/less.php": "v1.7.0.14",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^3.0.2",
    "symfony/assetic-bundle": "^2.8",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.3.10",
    "symfony/symfony": "3.3.*",
    "twig/twig": "^1.0||^2.0",
    "twitter/bootstrap": "^3.3",
    "white-october/pagerfanta-bundle": "^1.0"

I then have a template inside my AppBundle which extends base.html.twig:

{% extends 'base.html.twig' %}

{% block body %}
    <nav class="navbar navbar-inverse navbar-fixed-top">

...

    {% block content %}{% endblock %}

{% endblock %}

which in turn is extended by a page template:

{% extends '@AppBundle/index.html.twig' %}

{% block submenu %}
    <a href="{{ path('site_new') }}" class="btn btn-success"><i class="fa fa-plus"></i> Create</a>
{% endblock %}
{% block title %}
    Manage Sites
{% endblock %}
{% block body %}

    {{ pagerfanta(pager, 'twitter_bootstrap3') }}

{% endblock %}

Calling the template with

    $adapter = new DoctrineORMAdapter($qb);
    $pager = new Pagerfanta($adapter);
    $pager->setMaxPerPage(20);
    $pager->setCurrentPage(intval($this->getSessionPage()));

    $data = $pager->getCurrentPageResults();
    return $this->render('@AppBundle/site/index.html.twig', [
        'pager' => $pager,
        'data' => $data,
        'order' => $order,
        'form' => $form->createView()
    ]);   

However I'm getting

Unknown "pagerfanta" function.

Exception: Twig_Error_Syntax

Its as if this Twig function was not included, but I cannot see what else I need to include. Pagerfanta is in my AppKernel.php as well

jdog
  • 2,465
  • 6
  • 40
  • 74
  • I'm not sure if you already tied this or not, but did you clear your cache? Using: `php bin/console cache:clear --no-warmup --env=prod` or even `rm -Rf var/cache` I'm thinking you may have changed something but didn't clear your cache. – Alvin Bunk Jul 13 '17 at 05:07
  • Yes have cleared cache – jdog Jul 13 '17 at 08:53
  • This might be obvious, and I'm not really familiar with this stuff, but did you actually create your Pagerfanta object and register it with your template? – Kdawg Jul 17 '17 at 03:08
  • No it's a twig extension, I'm not supposed to do this legwork – jdog Jul 17 '17 at 07:17
  • Are you sure? The link to the documentation in svgrafov's answer suggests otherwise: "First, you'll need to pass an instance of Pagerfanta as a parameter into your template... You then call the the Pagerfanta Twig extension, passing in the Pagerfanta instance." What is the value of `$pager` in your code? – Kdawg Jul 17 '17 at 10:00
  • Please, can you show us this part where `WhiteOctoberPagerfantaBundle` is added to the `AppKernel.php`? – yceruto Jul 17 '17 at 17:36
  • 2
    @yceruto, doh, hadn't added it, even though I thought so. pls add an answer so I can accept it – jdog Jul 17 '17 at 19:14

3 Answers3

6

That looks like you've forgotten to add the WhiteOctoberPagerfantaBundle to the AppKernel.php, causing that PagerfantaExtension is not loaded, therefore the {{ pagerfanta() }} function is not defined.

$bundles = array(
    // ...
    new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
);
yceruto
  • 9,230
  • 5
  • 38
  • 65
0

I guess you have a typo somewhere near rendering this template. Add rendering code to your question, it should like like this.

https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle#rendering-pagerfantas

$adapter = new DoctrineORMAdapter($queryBuilder);
$pagerfanta = new Pagerfanta($adapter);
    return $this->render('@YourApp/Main/example.html.twig', [
    'my_pager' => $pagerfanta,
]);
svgrafov
  • 1,970
  • 4
  • 16
  • 32
0

using pagerfanta with Symfony 6

There is no AppKernel.php in it.

If you run into the same problem using Symfony 6 then you probably forgot to install the pagerfanta-bundle or the recipe didn't add the bundle to your bundle setting: config/bundles.php

<?php

return [
    ..
    BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
];

For Symfony 6 you need to install these 3 packages:

$ composer require pagerfanta/pagerfanta
$ composer require pagerfanta/twig
$ composer require babdev/pagerfanta-bundle
Zoltán Süle
  • 1,482
  • 19
  • 26