From 75162159fcc1df96ad48389d5165d0855904a62c Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 11 Apr 2024 12:43:41 +0200 Subject: [PATCH] [Twig] Expand the explanation about the humanize filter --- reference/twig_reference.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 481cbd23898..1c20264352c 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -391,9 +391,18 @@ humanize ``text`` **type**: ``string`` -Makes a technical name human readable (i.e. replaces underscores by spaces -or transforms camelCase text like ``helloWorld`` to ``hello world`` -and then capitalizes the string). +Transforms the given string into a human readable string (by replacing underscores +with spaces, capitalizing the string, etc.) It's useful e.g. when displaying +the names of PHP properties/variables to end users: + +.. code-block:: twig + + {{ 'dateOfBirth'|humanize }} {# renders: Date of birth #} + {{ 'DateOfBirth'|humanize }} {# renders: Date of birth #} + {{ 'date-of-birth'|humanize }} {# renders: Date-of-birth #} + {{ 'date_of_birth'|humanize }} {# renders: Date of birth #} + {{ 'date of birth'|humanize }} {# renders: Date of birth #} + {{ 'Date Of Birth'|humanize }} {# renders: Date of birth #} .. _reference-twig-filter-trans: