How to truncate a twig array [row] in a controller?

50 Views Asked by At

I have some twig arrays to display on a datatable.

              `  $values = array(
                $row['member'] . '-' . $row['email'],
                $row['transactionDate'],
                $row['currency'],
                $row['amount'],
                empty($row['amountReceived']) ? '0.00' : $row['amountReceived'],
                $row['status'],
                $row['status'] == 'Pending' ? $action : ''
            );`

That is on a controller, and it shows and works, but i want to truncate the member & email array result.

I have tried |truncate(5), but this does not work within the row variable.

Any ideas?

I have tried [email|truncate(5)], but this does not work within the row variable.

1

There are 1 best solutions below

1
craigh On

You need the Symfony String Component. This will install the u filter. Then you can use it to truncate your strings.

{{ row.email|u.truncate(8) }}

as @Leroy mentioned in his comment, you probably should use keys (like I have in the example above).

Docs ref