-
Notifications
You must be signed in to change notification settings - Fork 110
how to add a custom twig template ? #98
Comments
You can have a look at Pagerfanta's views: https://github.com/whiteoctober/Pagerfanta#views |
This does not really answer the question. I've spent countless hours trying and failing to create a custom template. If it is actually possible does anyone have a working example that we can look at? From what I've gathered I can add a
I then add a {{MyView}}View.php-file in my bundles
And then in my bundles
In my template I try to include it like this:
This code gives me the error: Most of this is not really documented, which is why I've had to sniff around the source code and guess how it works. Would be great with a demo template. |
If anybody is looking for answer to ibasaw's question, here is how you use custom views with this bundle: 1. Create View class (./src/Foo/BarBundle/View/MyView.php):namespace Foo\BarBundle\View;
use Pagerfanta\View\DefaultView;
use Foo\BarBundle\View\Template\MyTemplate;
class MyView extends DefaultView {
protected function createDefaultTemplate() {
return new MyTemplate();
}
protected function getDefaultProximity() {
return 3;
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'my';
}
} 2. Create Template class (./src/Foo/BarBundle/View/Template/MyTemplate.php):<?php
namespace Foo\BarBundle\View\Template;
class MyTemplate extends \Pagerfanta\View\Template\Template {
// copy contents of class from ./vendor/pagerfanta/pagerfanta/src/Pagerfanta/View/Template/TwitterBootstrapTemplate.php
// and adjust to your preferences
} 3. Add your new view class as service (./src/Foo/BarBundle/Resources/config/services.yml):services:
pagerfanta.view.my:
class: Foo\BarBundle\View\MyView
public: false
tags:
- { name: 'pagerfanta.view', alias: 'my' } 4. Use in your twig template:{{ pagerfanta(pager, 'my') }} |
@mirodav could you please update your answer for Symfony 4? |
@KirbyFox: The above example should already work for SF 4!? |
I would like to override the default template, and custom it with a template.html.twig file in my root views folder
Can't find anything on internet about it...
The text was updated successfully, but these errors were encountered: