arkounay/twig-copy-location-bundle
Installation:
composer require --dev arkounay/twig-copy-location-bundle
Enable the Bundle:
Add to config/bundles.php (if not auto-discovered):
Arkounay\TwigCopyLocationBundle\ArkounayTwigCopyLocationBundle::class => ['dev' => true],
First Use Case:
Debugging Twig Templates:
Ctrl+Shift+F or Cmd+Shift+O._layout.html.twig → homepage.html.twig).Controller Debugging:
App\Controller\ProductController::index) to jump to the controller class/method.Collaboration:
templates/product/_card.html.twig for the styling issue."IDE Shortcuts:
Ctrl+V → Ctrl+Shift+F).Ctrl+Shift+O) for instant navigation.Customizing the Panel:
# templates/bundles/ArkounayTwigCopyLocation/debug/twig_copy_location.html.twig
{% extends '@ArkounayTwigCopyLocation/debug/twig_copy_location.html.twig' %}
{% block title %}{{ parent() }} (Customized){% endblock %}
php bin/console cache:clear
Symfony Flex Compatibility:
services.yaml edits needed).CI/CD Pipelines:
dev environments (handled by composer.json require-dev).Missing Debug Toolbar:
APP_ENV=dev in .env.config/packages/dev/web_profiler.yaml).PHP Version Mismatch:
Class 'Arkounay\TwigCopyLocationBundle\...' not found.composer.json and run composer update.Twig Path Not Showing:
twig bundle is loaded (check config/bundles.php).Twig_Environment overrides the default one.use Symfony\Bundle\TwigBundle\TwigBundle;
// Ensure TwigBundle is enabled in bundles.php
Controller Path Empty:
kernel.controller event. If empty:
Log the Bundle’s Data:
Add this to config/packages/dev/debug.yaml to log Twig/controller paths:
services:
Arkounay\TwigCopyLocationBundle\EventListener\DebugListener:
arguments:
$logger: '@logger'
DEBUG entries like:
[TwigCopyLocation] Current Twig: templates/product/show.html.twig
[TwigCopyLocation] Current Controller: App\Controller\ProductController::showAction
Override the Copy Logic:
Extend the bundle’s DebugListener to customize copied data:
// src/EventListener/CustomDebugListener.php
namespace App\EventListener;
use Arkounay\TwigCopyLocationBundle\EventListener\DebugListener as BaseListener;
class CustomDebugListener extends BaseListener
{
public function getTwigPath(): string
{
$path = parent::getTwigPath();
return str_replace('templates/', 'src/Templates/', $path); // Example: Adjust paths
}
}
config/services.yaml:
services:
App\EventListener\CustomDebugListener:
tags: [kernel.event_listener]
arguments: ['@logger']
Add Custom Data: Extend the debug panel to include additional context (e.g., Git blame info):
{% block twig_data %}
{{ parent() }}
<div class="git-info">
{{ app.git_blame(twig_path) }}
</div>
{% endblock %}
Localize Paths: Convert Windows paths to Unix-style for cross-platform teams:
// Override DebugListener::getTwigPath()
return str_replace('\\', '/', $path);
Security Note:
/var/www/private/templates/).realpath() to normalize paths before copying:
return realpath($path) ?: $path;
Performance:
How can I help you explore Laravel packages today?