datatables-bundle icon indicating copy to clipboard operation
datatables-bundle copied to clipboard

Passing additional data to the TwigColumn template render

Open bertoost opened this issue 3 years ago • 3 comments

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',
    ],
]);

bertoost avatar Sep 08 '21 19:09 bertoost

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

Ahummeling avatar Jan 09 '22 23:01 Ahummeling

@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.

curry684 avatar Aug 10 '22 10:08 curry684

@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

Ahummeling avatar Aug 10 '22 10:08 Ahummeling

Stale issue message

github-actions[bot] avatar Nov 19 '22 22:11 github-actions[bot]