Closed FredDut closed 1 year ago
I forgot to say: apy/datagrid-bundle 4.0.2 symfony 5.4.7 php 7.2.24
HI, @FredDut it's seems to be a bug introduced here.
It's not TemplateWrapper
class that should be use but `Twig\Template
class
Hi @mhor , rolling back to Twig\Template is not enough. I've to change
public function setTemplate($template)
{
if (is_string($template)) {
if (substr($template, 0, 8) === '__SELF__') {
$this->templates = $this->getTemplatesFromString(substr($template, 8));
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} else {
$this->templates = $this->getTemplatesFromString($template);
}
} elseif ($this->templates === null) {
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} else {
throw new \Exception('Unable to load template');
}
return $this;
}
in
public function setTemplate($template)
{
if (is_string($template)) {
if (substr($template, 0, 8) === '__SELF__') {
$this->templates = $this->getTemplatesFromString(substr($template, 8));
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} else {
$this->templates = $this->getTemplatesFromString($template);
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
}
} elseif ($this->templates === null) {
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} else {
throw new \Exception('Unable to load template');
}
return $this;
}
or this
public function setTemplate($template)
{
if (is_string($template)) {
if (substr($template, 0, 8) === '__SELF__') {
$this->templates = $this->getTemplatesFromString(substr($template, 8));
} else {
$this->templates = $this->getTemplatesFromString($template);
}
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} elseif ($this->templates === null) {
$this->templates[] = $this->twig->loadTemplate(static::DEFAULT_TEMPLATE);
} else {
throw new \Exception('Unable to load template');
}
return $this;
}
but I don't really know what I'm doing I don't know why the DEFAULT_TEMPLATE is not loaded by getTemplatesFromString and why it was working before.
Hello @FredDut thank you for reporting this bug.
I've updated the demo repo here https://github.com/npotier/apydatagrid-demo to reproduce this case.
With the latest version of APYDatagridBundle, I don't reproduce this bug.
Could you try and confirm it please ?
Thank you 😄
Hello, I don't reproduce it anymore, neither do I. It's fixed. Thanks
Hello, If I use twigs for customizing a cell in the grid and and the grid globaly, the export fails with "Block "grid_titles" doesn't exist in grid template "ee"." An example based on https://github.com/npotier/apydatagrid-demo author/book in config/packages/twig.yaml:
templates/grid.html.twig:
templates/author/index.html.twig
templates/author/grid_template.html.twig `{% extends 'grid.html.twig' %}
{% block grid_column_id_cell %} here {{ value }} {% endblock %}`
AuthorController ` /**
@Route("/", name="author_index", methods={"GET", "POST"}) */ public function index(AuthorRepository $authorRepository, \APY\DataGridBundle\Grid\Grid $grid): Response { $source = new Entity(Author::class); // Attach the source to the grid $grid->setSource($source); $grid->addExport(new CSVExport('CSV Export', 'export')); return $grid->getGridResponse('author/index.html.twig',[ 'authors' => $authorRepository->findAll(), ]);
}`
Nota: same error if grid.html.twig doesn't extend blocks.html.twig