Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1014 Bytes

README.md

File metadata and controls

41 lines (31 loc) · 1014 Bytes

Twig Helpers

Installation

composer require dmt-software/twig-helpers

Usage

Tabular

First create a template that will render the tabular data. The following snippet shows an example of a twig template.

{% import 'theme/tabular/default-table.twig' as tab %}
 
{{ tab.tabular_start(table) }}
    {{ tab.header_row(table.columns) }}
    {{ tab.data_rows(table.resultSet, table.columns) }}
{{ tab.tabular_close() }}

In php create a table using the tabular builder, add a result set to it and render the template.

use DMT\Twig\Tabular\Builder;
use Twig\Environment;
 
$table = (new Builder())
    ->addColumn('id', '#')
    ->addColumn('username', 'name')
    ->addColumn('email')
    ->build();

/** @var iterable $userList */
$table->setResultSet($userList);
 
/** @var Environment $twig */
print $twig->render('example.twig', compact('table'));

This will render a html table for the $userList.

More documentation on tabular configuration and usage.