gatomontes / symfony-twig-route-tracer
Symfony bundle that adds route trace anchors to Twig templates for IDE navigation.
Package info
github.com/gatomontes/symfony-twig-route-tracer
Type:symfony-bundle
pkg:composer/gatomontes/symfony-twig-route-tracer
v0.1.0
2026-05-18 17:29 UTC
Requires
- php: >=8.1
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
- symfony/routing: ^6.4 || ^7.0 || ^8.0
- twig/twig: ^3.0
README
A DX package for Symfony + Twig projects.
Installation
composer require gatomontes/symfony-twig-route-tracer:^0.1 --dev
Problem
Twig to controller navigation in PhpStorm is painful.
This package injects non-rendering route traces into Twig templates so IDE route navigation can be reused.
Example:
{% if false %}
{# trace_route:start #}
{% set __symfony_twig_route_tracer_app_organization_index = path('app_organization_index') %}
{# trace_route:end #}
{% endif %}
The trace never executes at runtime.
Its purpose is IDE navigation.
Commands
Inject a single route:
php bin/console tracer:inject --route=app_organization_index
Preview a route injection without writing files:
php bin/console tracer:inject --route=app_organization_index --dry-run
Inject all routes:
php bin/console tracer:inject
Injection Rules
- additive
- idempotent
- no duplicates
- alphabetically sorted
- validates generated Twig before writing
- supports
--dry-runpreviews for safe review
MVP Notes
- route resolution uses Symfony router metadata
- template resolution scans controller source for
$this->render('...') - template resolution also follows
renderView()calls and local service/document-builder methods that contain Twig template literals - injected traces use native Twig
path()calls so IDEs can reuse Symfony route recognition - traces are wrapped in
{% if false %}so routes with required params never execute at runtime - namespaced Twig templates such as
@Admin/foo.html.twigare not supported yet
Known Limitations
- template discovery is static and source-based; highly dynamic template selection may not be traced
- namespaced Twig template references such as
@Admin/foo.html.twigare not resolved yet - service traversal is limited to local project services and Twig template string literals
Goals
- Twig -> controller navigation
- leverage existing Symfony route intelligence
- avoid custom IDE plugins
- MakerBundle integration