Skip to content

Commit f0e841b

Browse files
author
Tim Herlaud
committed
[String] Add TruncateMode mode to truncate methods
1 parent d4f51e6 commit f0e841b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

string.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,15 @@ Methods to Join, Split, Truncate and Reverse
394394
u('Lorem Ipsum')->truncate(3); // 'Lor'
395395
u('Lorem Ipsum')->truncate(80); // 'Lorem Ipsum'
396396
// the second argument is the character(s) added when a string is cut
397+
// the third argument is TruncateMode::Char by default
397398
// (the total length includes the length of this character(s))
398-
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
399-
// if the third argument is false, the last word before the cut is kept
400-
// even if that generates a string longer than the desired length
401-
u('Lorem Ipsum')->truncate(8, '…', cut: false); // 'Lorem Ipsum'
399+
u('Lorem Ipsum')->truncate(8, '…'); // 'Lorem I…'
400+
// new enum options to keep complete words
401+
u('Lorem ipsum dolor sit amet')->truncate(10, '...', TruncateMode::WordBefore); // 'Lorem...'
402+
u('Lorem ipsum dolor sit amet')->truncate(14, '...', TruncateMode::WordAfter); // 'Lorem ipsum...'
403+
404+
.. versionadded:: 7.2
405+
The TruncateMode argument for truncate function was introduced in Symfony 7.2.
402406

403407
::
404408

0 commit comments

Comments
 (0)