gatomontes/symfony-twig-route-tracer

Symfony bundle that adds route trace anchors to Twig templates for IDE navigation.

Maintainers

Package info

github.com/gatomontes/symfony-twig-route-tracer

Type:symfony-bundle

pkg:composer/gatomontes/symfony-twig-route-tracer

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-05-18 17:29 UTC

This package is auto-updated.

Last update: 2026-07-19 15:08:52 UTC


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-run previews 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.twig are 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.twig are 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