Skip to content

Template Collector ​

Captures template/view rendering with optional timing, output capture, parameters, and duplicate detection. Works with any template engine (Twig, Blade, PHP templates, etc.).

What It Captures ​

FieldDescription
templateTemplate file path or name
renderTimeRendering duration in seconds (optional, 0 if not measured)
outputRendered output HTML (optional, empty if not captured)
parametersParameters passed to the template (optional)

Data Schema ​

json
{
    "renders": [
        {
            "template": "home/index.html.twig",
            "renderTime": 0.0045,
            "output": "",
            "parameters": []
        },
        {
            "template": "/app/views/user/profile.php",
            "renderTime": 0,
            "output": "<div class=\"profile\">...</div>",
            "parameters": {"user": "object@App\\Entity\\User#42"}
        }
    ],
    "totalTime": 0.0045,
    "renderCount": 2,
    "duplicates": {
        "groups": [],
        "totalDuplicatedCount": 0
    }
}

Summary (shown in debug entry list):

json
{
    "template": {
        "renderCount": 2,
        "totalTime": 0.0045,
        "duplicateGroups": 0,
        "totalDuplicatedCount": 0
    }
}

Contract ​

Two entry points depending on available data:

php
use AppDevPanel\Kernel\Collector\TemplateCollector;

// Template engines with timing (Twig, Blade)
$collector->logRender(
    template: 'home/index.html.twig',
    renderTime: 0.0045,
);

// View systems with output capture (Yii views, PHP templates)
$collector->collectRender(
    template: '/app/views/user/profile.php',
    output: '<div class="profile">...</div>',
    parameters: ['user' => $userObject],
    renderTime: 0.003, // optional
);

How It Works ​

Framework adapters hook into the template/view rendering system:

Debug Panel ​

  • Summary cards — total templates rendered, aggregate render time (when timing available)
  • Template list — all rendered templates with file paths and render time
  • Output preview — rendered HTML output (expandable, when captured)
  • Parameters — expandable view parameters (when captured)
  • Duplicate detection — highlights repeated renders of the same template (N+1 issues)
  • Flat / Grouped views — toggle between all renders and grouped duplicates

Released under the MIT License.