Skip to content
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

Document Twig vs PHP types #4362

Merged
merged 1 commit into from
Sep 30, 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
20 changes: 18 additions & 2 deletions doc/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,24 @@ Twig templates have access to variables provided by the PHP application and
variables created in templates via the :doc:`set <tags/set>` tag. These
variables can be manipulated and displayed in the template.

Use a dot (``.``) to access attributes of a variable (methods, properties
or constants of a PHP object, or items of a PHP array):
Twig tries to abstract PHP types as much as possible and works with a few basic
types, supported by ``filters``, ``functions``, and ``tests`` among others:

=================== ===============================
Twig Type PHP Type
=================== ===============================
string A string or a Stringable object
number An integer or a float
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docs int is used here: https://twig.symfony.com/doc/3.x/tags/types.html#types
Do we specify for the new feature PHP types instead of Twig types?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

While the documentation states "The syntax for and contents of type strings are intentionally left out of scope", I do agree that "number" and "boolean" are better choices to align with the documentation on types.

I'll create a PR for updating the types documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Voila: #4403

boolean ``true`` or ``false``
null ``null``
iterable (mapping) An array
iterable (sequence) An array
iterable (object) An iterable object
object An object
=================== ===============================

The ``iterable`` and ``object`` types expose attributes you can access via the
dot (``.``) operator:

.. code-block:: twig

Expand Down