victoire/render-widget
A Laravel package for rendering reusable widgets from PHP classes and Blade views, helping organize view logic and compose clean, maintainable UI blocks across your application.
Treat this as a legacy Symfony bundle first, not a greenfield dependency. Before installing, check composer.json in the repository for PHP and Symfony version constraints; the last release was April 2019, so expect Symfony 3.x/4.x-era code rather than Symfony 6/7 compatibility.
Minimal setup:
composer require victoire/render-widget
Enable the bundle using the convention for your Symfony version. For Symfony 3:
// app/AppKernel.php
$bundles[] = new Victoire\WidgetRenderBundle\VictoireWidgetRenderBundle();
For Symfony 4+ Flex-style apps:
// config/bundles.php
return [
// ...
Victoire\WidgetRenderBundle\VictoireWidgetRenderBundle::class => ['all' => true],
];
Confirm the actual bundle class name from the repository’s bundle class and composer.json; old Victoire bundles sometimes use non-obvious namespaces.
Where to look first:
README.md for the supported Twig function or service name.Resources/config/services.* for the renderer service ID and aliases.First practical use case: render a widget from a Twig template instead of hardcoding its controller/template. In a Victoire-style page layout that usually looks like:
{# Confirm the exact function name/signature from the installed Twig extension. #}
{{ render_widget(widget) }}
If the package exposes an ID-based API instead, it may look like:
{{ render_widget(widget.id) }}
Start by rendering one known widget in a simple template, then wire it into the page/template layout only after the output and cache behavior are understood.
Twig-first rendering. The main day-to-day use is likely a Twig function that takes a widget object or identifier and returns rendered markup. Keep widget rendering in templates where editors expect it, and keep controllers thin.
Controller/service rendering for non-Twig contexts. For emails, JSON APIs, PDFs, or CLI-generated pages, inject the renderer service directly rather than calling Twig. Find the service ID with:
bin/console debug:container render
bin/console debug:container --tag=twig.extension
Then wrap it in your own application service:
final class WidgetPresenter
{
public function __construct(private $widgetRenderer) {}
public function present(Widget $widget): string
{
return $this->widgetRenderer->render($widget);
}
}
Page-layout integration. In a CMS page template, iterate the page’s widget map and render each widget through the bundle:
{% for widget in page.widgets %}
<section class="widget widget--{{ widget.type }}">
{{ render_widget(widget) }}
</section>
{% endfor %}
This keeps widget-specific templates inside the widget package and avoids a giant switch in the page template.
Cache per widget. Widget rendering is a natural fragment boundary. Use Symfony fragment caching or ESI where possible:
{{ render_esi(controller('App\\Controller\\WidgetController::show', {id: widget.id})) }}
If you use the bundle’s Twig function directly, add your own cache key around it and include the widget’s updatedAt value so editor changes invalidate output.
AJAX/dynamic widgets. For widgets that change after page load, render a shell in Twig and fetch the widget endpoint from JavaScript. Keep the endpoint authenticated/authorized the same way as the page; do not rely on the widget ID being unguessable.
Testing pattern. Create a fixture widget, render it through the bundle in a kernel/functional test, and assert the expected markup. This catches template-resolution and service-wiring failures early, which matters more here because the package has little community usage.
composer.json, and be prepared to fork or vendor the bundle.composer why-not symfony/framework-bundle and check the bundle class before debugging templates.render_widget, widget_render, or a service call. Inspect the Twig extension class; do not assume from the package name.@VictoireWidgetRender/... paths. Use bin/console debug:twig to list namespaces and bin/console lint:twig templates to catch bad references.updatedAt. Otherwise editors will change a widget and see stale output.bin/console debug:container, debug:twig, and lint:twig will usually locate wiring/template issues faster than reading the bundle source.How can I help you explore Laravel packages today?