omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
251 stars 113 forks source link

Passing additional data to the TwigColumn template render #238

Closed bertoost closed 1 year ago

bertoost commented 2 years ago

Currently you can only render a Twig template and it passes the current row and the normal value to the template. It would be cool to have the ability to add more values to the view.

$table->add('field', TwigColumn::class, [
    'template' => 'tenant/students/snippets/overview/courses.html.twig',
    'variables' => [             // <-- Add-in extra variables to the view
        'var' => 'value',
    ],
]);
Ahummeling commented 2 years ago

From my understanding, this is already possible:

$table->add('field', TwigColumn::class)->setTemplate('tenant/students/snippets/overview/courses.html.twig', ['var' => 'value']);

However, I do agree that it is strange that the TwigColumn does not support this by default, so I added a PR for the feature. #254

curry684 commented 1 year ago

@Ahummeling that is NOT the same. that code runs setTemplate on the DataTable instance, not the column. It overrides the rendering of the entire table.

Ahummeling commented 1 year ago

@Ahummeling that is NOT the same. that code runs setTemplate on the DataTable instance, not the column. It overrides the rendering of the entire table.

Oh, I see. My bad, sorry! Thanks for clarifying

github-actions[bot] commented 1 year ago

Stale issue message