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 1 commit
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
44 changes: 34 additions & 10 deletions cookbook/profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,51 @@ 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 #}
{# Used for the menu items along the 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 roll-over</b>
<b>info here</b>
</div>
{% endset %}

{# Omit this next line if you do not have a "panel" section #}
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 not omit the whole line (otherwise your item is not rendered at all) but only the with { 'link': true } part (or setting it to false)

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 Right, my mistake.

{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': true } %}

{% endblock %}

Copy link
Member

Choose a reason for hiding this comment

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

please don't add trailing spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably they are leading spaces :) I was erring on the side of caution in case omitting them would cause the example to render as separate code-blocks.

{% 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 #}
{# The left-hand menu content when looking at profiler data. #}
<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