Installation:
composer require amp/subrequestextra-bundle:dev-master
Add to AppKernel.php (Symfony 2.x):
new Amp\SubrequestExtraBundle\AmpSubrequestExtraBundle(),
(Only in dev/test environments.)
Enable Debug Toolbar:
Ensure framework.router.request_context.query.string includes ?_debug_toolbar=on or use the toolbar icon in the browser.
First Use Case: Render a subrequest in Twig:
{% render 'AcmeBundle:Controller:action' %}
Toggle the Subrequests tab in the Web Debug Toolbar to visualize the rendered subrequest.
Debugging Subrequests:
{% render %} call by checking its parameters, execution time, and response.Ignoring Specific Controllers:
Configure amp_subrequest_extra.ignore_controllers in config.yml to exclude non-critical subrequests:
amp_subrequest_extra:
ignore_controllers:
- AcmeBundle:Admin:dashboard # Exclude admin dashboard subrequests
Integration with Custom Templates: Extend Twig templates to include subrequests dynamically:
{% for item in items %}
{% render 'AcmeBundle:Item:partial', { item: item } %}
{% endfor %}
Verify subrequests in the toolbar for each loop iteration.
Performance Profiling: Compare execution times of subrequests to identify bottlenecks. Use the toolbar’s timing metrics.
Conditional Rendering: Wrap subrequests in logic to avoid clutter:
{% if debug %}
{% render 'AcmeBundle:Debug:metrics' %}
{% endif %}
Toggle visibility via debug context.
Parameter Validation: Pass parameters explicitly to subrequests and validate them in the toolbar:
{% render 'AcmeBundle:User:profile', { userId: user.id, locale: app.request.locale } %}
Toolbar Dependency:
_debug_toolbar=on is set. Test in dev mode or append ?_debug_toolbar=on to URLs.Ignored Controllers:
ignore_controllers may hide critical subrequests. Verify the exact format (e.g., Bundle:Controller:action).Empty Responses:
Subrequests returning empty responses (e.g., new Response()) may not render in the toolbar. Use {% render %} with non-empty content for visibility.
Symfony 3+/4+ Compatibility:
Check Subrequest Parameters:
The toolbar displays passed parameters. Mismatches (e.g., missing id) can cause silent failures.
Template Caching:
Clear cache (php bin/console cache:clear) if subrequests disappear after configuration changes.
Extension Points: Override the default Twig wrapper by extending the bundle’s template:
# app/Resources/AmpSubrequestExtraBundle/views/Subrequest/container.html.twig
{% extends 'AmpSubrequestExtraBundle:Subrequest:container.html.twig' %}
{% block subrequest_content %}
{{- parent() -}}
<div class="custom-metrics">{{ subrequest.metrics }}</div>
{% endblock %}
Toolbar Overhead:
Enabling subrequest debugging adds minor latency. Disable in production (%prod% environments).
Memory Usage:
Deeply nested subrequests may increase memory usage. Monitor with memory_get_usage().
How can I help you explore Laravel packages today?