Skip to content

[Twig] Expand the explanation about the humanize filter #19774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down