Rendering¶
Rendering is performed using the DebugBar\JavascriptRenderer class. It contains
all the useful functions to include the needed assets and generate a debug bar.
Assets¶
The debug bar relies on some css and javascript files which needs to be included into your webpage. They are located in the resources folder. Additionally, asset providers may provide inline assets that have to be embedded directly in the HTML. This can be done in four ways:
- Using
JavascriptRenderer::renderHead()usingsetBaseUrl()to point to the asset folder directly - Using
JavascriptRenderer::renderHead()usingsetAssetHandlerUrl()to point to the AssetHandler - Dumping the assets yourself using
JavascriptRenderer::dumpCssAssets(),JavascriptRenderer::dumpJsAssets(), andJavascriptRenderer::dumpHeadAssets(). - Retrieving filenames and inline content of assets using
JavascriptRenderer::getAssets()and doing something with it
You can define the base url of your assets using setBaseUrl(), or set the AssetHandler with setAssetHandlerUrl() (see below).
Using renderHead():
Dumping the assets:
Retrieving the assets:
Asset Handler¶
The AssetHandler can be used to serve assets from a different location than the default.
You can then implement an endpoint with the AssetHandler in your application to serve the assets from a different location.
Make sure you add the same collectors to the DebugBar instance you use in the AssetHandler, as in your main application. Otherwise not all assets will be available. The minified files usually include all assets.
Vendor assets¶
Note that you can only use the debug bar assets and manage the dependencies by yourself
using $renderer->setIncludeVendors(false). Instead of false, css or js may be used
to only include css or js assets of vendors.
Minified dist files¶
By default, the debug bar uses the minified files from the dist folder. These are generated automatically and include all vendor and widget files.
If you want to use the non-minified files, you can set $renderer->useDistFiles(false).
When using dist files, any additional scripts or inline scripts/styles will still be included.
The Javascript object¶
The renderer will generate all the needed code for your debug bar. This means initializing the DebugBar js object, adding tabs and indicators, defining a data map, etc...
Data collectors can provide their own controls when implementing the
DebugBar\DataCollector\Renderable interface as explained in the Collecting Data chapter.
Thus in almost all cases, you should only have to use render() right away:
This will print the initialization code for the toolbar and the dataset for the request.
When you are performing AJAX requests, you do not want to initialize a new toolbar but
add the dataset to the existing one. You can disable initialization using false as
the first argument of render().