Skip to content

Flesh out twig-template for custom data-collector #5115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions cookbook/profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,56 @@ Adding Web Profiler Templates
-----------------------------

When you want to display the data collected by your data collector in the web
debug toolbar or the web profiler, create a Twig template following this
skeleton:
debug toolbar or the web profiler, you will need to create a Twig template. The
following example can help you get started:

.. code-block:: jinja

{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}

{% block toolbar %}
{# the web debug toolbar content #}
{# This toolbar item may appear along the top or bottom of the screen.#}
{% set icon %}
<span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAcCAQAAADVGmdYAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQffAxkBCDStonIVAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAHpJREFUOMtj3PWfgXRAuqZd/5nIsIdhVBPFmgqIjCuYOrJsYtz1fxuUOYER2TQID8afwIiQ8YIkI4TzCv5D2AgaWSuExJKMIDbA7EEVhQEWXJ6FKUY4D48m7HYU/EcWZ8JlE6qfMELPDcUJuEMPxvYazYTDWRMjOcUyAEswO+VjeQQaAAAAAElFTkSuQmCC" alt=""/></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should recommend using a SVG image IMO, as done in the latest version of Symfony

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to just add a comment here instead of the image, this will avoid scrollbars. E.g:

{% block toolbar %}
    {# used for the menu items along the bottom of the screen. #}
    {% set icon %}
    <span class="icon">
        <!-- ... your icon image, it is recommended to use an SVG image for best quality -->
    </span>
    {% endset %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with both of you. I also think that we need to explicitly tell the user that the common practice is to inline icon contents, no matter if it's a base64-encoded PNG or inlined SVG file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof I think that would be good for the 2.7 branch of the documentation, but for the 2.6-version of each cookbook entry should reflect the 2.6 practice, which as far as I can tell is all PNGs. In other words, let's do that as a separate pull-request.

@wouterj I'd rather keep the actual image, because it provides the user a concrete, working example to build from. Having a scrollbar appear within the black code-sample box is a very small price to pay, especially since most users will probably copy-paste the whole thing and tinker with it outside the web-browser.

<span class="sf-toolbar-status">Example</span>
{% endset %}

{% set text %}
<div class="sf-toolbar-info-piece">
<b>Quick piece of data</b>
<span>100 units</div>
</div>
<div class="sf-toolbar-info-piece">
<b>Another quick thing</b>
<span>300 units</div>
</div>
{% endset %}

{# Set the "link" value to false if you do not have a big "panel"
section that you want to direct the user to. #}
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': true } %}

{% endblock %}

{% block head %}
{# if the web profiler panel needs some specific JS or CSS files #}
{# Optional, if you need your own JS or CSS files. #}
{{ parent() }} {# Use parent() to keep the default styles #}
{% endblock %}

{% block menu %}
{# the menu content #}
{# This left-hand menu appears when using the full-screen profiler. #}
<span class="label">
<span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAcCAQAAADVGmdYAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQffAxkBCDStonIVAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAAHpJREFUOMtj3PWfgXRAuqZd/5nIsIdhVBPFmgqIjCuYOrJsYtz1fxuUOYER2TQID8afwIiQ8YIkI4TzCv5D2AgaWSuExJKMIDbA7EEVhQEWXJ6FKUY4D48m7HYU/EcWZ8JlE6qfMELPDcUJuEMPxvYazYTDWRMjOcUyAEswO+VjeQQaAAAAAElFTkSuQmCC" alt=""/></span>
<strong>Example Collector</strong>
</span>
{% endblock %}

{% block panel %}
{# the panel content #}
{# Optional, for showing the most details. #}
<h2>Example</h2>
<p>
<em>Major information goes here</em>
</p>
{% endblock %}

Each block is optional. The ``toolbar`` block is used for the web debug
Expand Down