Skip to content

[Profiler] rendered templates always show the vendor one. #27911

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
lerminou opened this issue Jul 10, 2018 · 13 comments
Closed

[Profiler] rendered templates always show the vendor one. #27911

lerminou opened this issue Jul 10, 2018 · 13 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) RFC RFC = Request For Comments (proposals about features that you want to be discussed) WebProfilerBundle

Comments

@lerminou
Copy link
Contributor

Symfony version(s) affected: 4.1

Description
In the Web-Profiler component the section 'Rendered Templates' seems to show the template from vendor when we override one of them

When we mouse-on the template, the path is good (to the vendor directory or the overriden one) but the label always show @FOSUser/layout.html.twig.

Is there any issue here ? it's difficult to really see which templates are rendered.
Maybe an @app/@FOSUser/layout.html.twig can help to show overriden files ?

How to reproduce
I tried with the FOSUserBundle layout.thig file.
The base template is vendor/friendsofsymfony/user-bundle/Resources/views/layout.html.twig

I override this template in the following directory : templates/bundles/FOSUserBundle/layout.html.twig

Please, have a look at the screenshots.

Additional context
From app directory:
overriden template

From vendor:
base template

@xabbuh xabbuh added WebProfilerBundle RFC RFC = Request For Comments (proposals about features that you want to be discussed) DX DX = Developer eXperience (anything that improves the experience of using Symfony) labels Jul 10, 2018
@xabbuh
Copy link
Member

xabbuh commented Jul 10, 2018

IMO that's expected. What you see here is the template name. To which path that is resolved depends on which template files actually do exist in your application. Maybe we could add another column including the filename relative to the project directory though.

@stof
Copy link
Member

stof commented Jul 10, 2018

That's because @FOSUser/layout.html.twig is not a path at all. When you override a template, you don't change the template name. You change the source file being used for this name. The template being rendered is still called @FOSUser/layout.html.twig (and this is the reason why FOSUserBundle is able to use your overriding template without having to be told about its existence: it does not have a different name)

@lerminou
Copy link
Contributor Author

Thanks for your answer.
Maybe we can implement a visual effect (to define) to indicate that the template is overriden?

@ro0NL
Copy link
Contributor

ro0NL commented Jul 10, 2018

it's difficult to really see which templates are rendered

The list is clear, these are all "Rendered templates"

Is there any issue here ?

I'd say no :) Basically why do you want to know it's a vendor or app template upfront? It's being rendered either way...

Not that im against a little hint though, in terms of exposing as much as possible :)

@apfelbox
Copy link
Contributor

I think the point about the template name not being a path but only a logical name is quite clear by now.

But I also see, that the there is a very valid use case here. If I am debugging an issue with wrong rendering, I want to see at a glance which actual template file was rendered and not just the logical name. Because when searching for a bug, the logical name doesn't help too much.

@stof
Copy link
Member

stof commented Jul 10, 2018

Maybe we can implement a visual effect (to define) to indicate that the template is overriden?

that would require extra work, because it would force to look for all potential location for this template name (to see whether there are multiple existing files) instead of just reading the info from the template object.
Thus, that's not even something the Twig loader allows doing (as its job is to find the source to use, not all other potential sources to ignore).

@yceruto
Copy link
Member

yceruto commented Jul 10, 2018

Perhaps showing the relative path could help a bit to quickly understand which file was rendered:

rendered-templates

@lerminou
Copy link
Contributor Author

Or to be more compact as actual. We can check if the path begins by 'vendor/'. And if not then we can show a little button or message
@apfelbox yes. I was debugging too and that was the origin of my question.

@ro0NL
Copy link
Contributor

ro0NL commented Jul 11, 2018

I like the proposal by @yceruto, agree a filepath reference is more recognizable then its logical name. Currently you have to hover each link for that.

I don't see any real reason to treat vendor/ templates any different then non-vendor templates, e.g. visually. That's not really relevant IMHO.

@apfelbox
Copy link
Contributor

I would just take the proposal by @yceruto as is. 👌

@yceruto
Copy link
Member

yceruto commented Jul 11, 2018

We could also add a new option to the debug:twig command to look for template paths:

$ bin/console debug:twig --find=@FOSUser/layout.html.twig
templates/bundles/FOSUserBundle/layout.html.twig (default)
vendor/friendsofsymfony/user-bundle/Resources/views/layout.html.twig

We would see all the possible templates that match the given name and the search could be easier.

@yceruto
Copy link
Member

yceruto commented Jul 17, 2018

Proposal #27978 to improve the Twig panel is ready ;)

@yceruto
Copy link
Member

yceruto commented Jul 17, 2018

and see #27981 for a debug command ;)

fabpot added a commit that referenced this issue Jul 18, 2018
… and improving panel view (yceruto)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[WebProfilerBundle] Show relative path of the template and improving panel view

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27911
| License       | MIT
| Doc PR        | -

| Before | After |
| --- | --- |
| ![twig-panel-before](https://user-images.githubusercontent.com/2028198/42819536-dfbed0c6-89a1-11e8-8eb1-8151172e1ad7.png) | ![twig-panel-after](https://user-images.githubusercontent.com/2028198/42819544-e5e73182-89a1-11e8-9d49-80e343040260.png) |

#27978 (comment):

| Before | After |
| --- | --- |
| ![twig-toolbar-icon-before](https://user-images.githubusercontent.com/2028198/42820333-e35684c0-89a3-11e8-8b3a-f02bb835103c.png) | ![twig-toolbar-icon-after](https://user-images.githubusercontent.com/2028198/42820342-eac3a95e-89a3-11e8-929e-ef4fb1e392bb.png)
| ![twig-profiler-icon-before](https://user-images.githubusercontent.com/2028198/42820356-f3f04b72-89a3-11e8-9209-41ed37cf0915.png) | ![twig-profiler-icon-after](https://user-images.githubusercontent.com/2028198/42820370-fef24336-89a3-11e8-9b09-5ba1bf97df67.png) |

In addition, I added some visual improvements.

Commits
-------

bcd8058 Show relative path of the template and improving panel view
@fabpot fabpot closed this as completed Sep 5, 2018
fabpot added a commit that referenced this issue Sep 5, 2018
…wig command to find their paths (yceruto)

This PR was squashed before being merged into the 4.2-dev branch (closes #27981).

Discussion
----------

[TwigBridge] Added template "name" argument to debug:twig command to find their paths

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27911
| License       | MIT
| Doc PR        | symfony/symfony-docs#10232

Find the template file (to load by Twig) from a given template name (useful to know which file will be loaded exactly and which ones don't):
![debug-twig-loader-overridden](https://user-images.githubusercontent.com/2028198/42849959-81a8c49a-89f3-11e8-8d93-21581fe606a9.png)
This will also show the overridden files if they exist and the paths corresponding to their namespace.

In addition, the command suggests alternatives if you made a typo (this way you can check your template name quickly):

| namespace typo | template name typo |
| --- | --- |
| ![debug-twig-loader-ns-typo-alt](https://user-images.githubusercontent.com/2028198/42850624-81803e3c-89f6-11e8-8a92-11f09c99d13c.png) | ![debug-twig-loader-typo-alt](https://user-images.githubusercontent.com/2028198/42850644-99571238-89f6-11e8-9cf7-ed9b880f3d81.png) |

<details>
<summary><strong>Other outputs</strong></summary>

Discovering more alternatives:
![debug-twig-loader-not-found-many-alt](https://user-images.githubusercontent.com/2028198/42850815-82a30eb0-89f7-11e8-8d23-530f8ff325bc.png)

Unknown template name:
![debug-twig-loader-not-found](https://user-images.githubusercontent.com/2028198/42850882-d647aad0-89f7-11e8-9735-94149895437f.png)
</details>

## Update
The feature was introduced into `debug:twig` command and the `filter` argument was converted to `--filter` option. The `name` argument is now the first one of the command.

Commits
-------

7ef3d39 [TwigBridge] Added template \"name\" argument to debug:twig command to find their paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) RFC RFC = Request For Comments (proposals about features that you want to be discussed) WebProfilerBundle
Projects
None yet
Development

No branches or pull requests

7 participants