-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Standardize Twig comment annotations for documenting template variables and blocks #4768
Description
For Symfony UX Toolkit, I've been using a simple format to document TwigComponent APIs directly in Twig comments:
{# @prop id string Unique identifier for the Accordion #}
{# @prop multiple boolean Whether multiple items can be opened at once #}
{# @prop defaultValue string|array<string>|null Value(s) of the item(s) to open by default #}
{# @block content The accordion items #}Live example: https://ux.symfony.com/toolkit/kits/shadcn/components/accordion#content-api-reference
This format is human-readable and easy to parse. It's inspired by PHPDoc's @property, though with a different order: @prop <name> <type> <description> instead of @property <type> $<name> <description>.
It was a mistake, and will be fixed ASAP.
Why standardize?
I've opened Haehnchen/idea-php-symfony2-plugin#2545 to add syntax highlighting for @prop (or @property) and @block in the PhpStorm Symfony plugin.
It would be better to standardize the format first, especially before implementing auto-completion.
Beyond Symfony UX, I think this could be useful for plain Twig templates too.
For instance, @prop could help IDEs suggest variables when using {{ include() }}:
{# _card.html.twig #}
{# @prop title string The title #}
{# @prop description string|null The description #}
{# IDE could auto-suggest 'title' and 'description' here: #}
{{ include('_card.html.twig', { ... }) }}In the future, we can even imagine deprecating templates with a @deprecated annotation, etc...
WDYT? Thanks!