-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WebProfilerBundle] Render file links for twig templates #24236
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
Conversation
@pquerner ive tested this with the RemoteCall plugin.. and results are impressive i must say. Good news is for SF this works out-of-the-box with
AFAIK there's no real need for making this an XHR call (but i tested this only in chrome, which magically also preserves the current URL). As a result im experimenting with integration in the toolbar. Works perfect; thus super fast template navigation. Needs some CSS. |
The Magento Module does it via XHR aswell, so there are no unneeded browser tabs. Impressive work so far. On a page with loads of templates the select box are not very helpful I guess, since you cant "spot" the right template from it as quick as from the profiler template page. Maybe limit results in that select box or make it optional via configuration? |
SF doesnt add Access from the WDT is really worth it.. so i hope we can do something. Ideally has "select as you type". cc @javiereguiluz @ogizanagi (as you wrote dumper search thingy) |
Select as you type would mean you have a small idea on the templates filename. Which is not the case when working on a project you just took over for instance? I dont know. Hard to spec this out I guess. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the proposed changes.
About this other proposal for the debug toolbar, I don't like it at all. It doesn't look right to put that in the toolbar.
Agree, it's experimental really. Also from a "navigate to used templates" pov, this saves a profiler visit. So again; if we can do something that be awesome. However the issue of many templates is real; so i can imagine we wont be able to integrate this properly in the toolbar. |
Well, I just opened a page of my own project and looked at the number of templates listed in the profiler. There are 35 (I have a deeper inheritance hierarchy than just a single layout, and a bunch of helper templates being included for reusable parts). I don't think this would fit in the toolbar itself (and I actually rarely open files from the profiler btw, so a big selector would actually annoy me) |
|
||
if (null !== $this->loader) { | ||
$locator = (new \ReflectionObject($this->loader))->getMethod('findTemplate'); | ||
$locator->setAccessible(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 for using private APIs of the Twig filesystem loader. This is calling for issues (there is no BC for internal APIs, even in patch releases).
Thus, your logic does not work in case multiple loaders are used (the template may have been loaded by a different loader and so come from a different file).
you should use public Twig APIs instead:
$source = $twig->load($name)->getSourceContext();
$path = $source->getPath(); // Be careful. May be null if loader took it from elsewhere than the filesystem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe $twig->loadTemplate($profile->getTemplate())->getSourceContext()->getPath()
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ro0NL please, don't forget about this minor change needed to merge this. Thanks!
Status: needs work |
Updated. All good :) tested on real life project. status: needs review |
Thank you @ro0NL. |
…es (ro0NL) This PR was squashed before being merged into the 3.4 branch (closes #24236). Discussion ---------- [WebProfilerBundle] Render file links for twig templates | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | #24218 | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features-->  Also tweaked default code color a bit for yaml, twig and the like. Before  After  Commits ------- 860575a [WebProfilerBundle] Render file links for twig templates
I get the following error in my browser console:
Link:
Windows 10 x64 If I browse to that URL by hand it correctly opens the file in my IDE. //Edit //Edit2
Maybe Symfony has a method somewhere which escapes the string for you? |
@pquerner my PR didnt include any JS, do you put this in |
No I just installed the dev branch of 3.4 and looked at your work. I didnt configure anything. 9ebe218#diff-d586a5424c06b09812bbfd9e8c266456R90 Does render the link variable, I dont where it is generated or how. |
link is based on So im not sure where |
What did your URL look like if not called via XHR? |
Literally as posted in #24236 (comment) plain |
Ignore my issues here, everything is fine. #24356 (comment) |
private $computed; | ||
|
||
public function __construct(Profile $profile) | ||
public function __construct(Profile $profile, Environment $twig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a BC break. It should be optional. @ro0NL Can you submit a PR to fix this?
…tor constructor (GawainLynch) This PR was merged into the 2.0.x-dev branch. Discussion ---------- Add Twig environment service parameter to TwigDataCollector constructor This is a BC break introduced upstream in symfony/symfony#24236 Commits ------- de4ce77 Add Twig environment service parameter to TwigDataCollector constructor
…o0NL) This PR was squashed before being merged into the 3.4 branch (closes #24851). Discussion ---------- [TwigBridge] Fix BC break due required twig environment | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | symfony/symfony#24236 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> See ezsystems/ezplatform-design-engine#12 + silexphp/Silex-WebProfiler#126 + bolt/bolt#7154 Sorry for that :) cc @fabpot Commits ------- 243e4b2 [TwigBridge] Fix BC break due required twig environment
…o0NL) This PR was squashed before being merged into the 3.4 branch (closes #24851). Discussion ---------- [TwigBridge] Fix BC break due required twig environment | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | #24236 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> See ezsystems/ezplatform-design-engine#12 + silexphp/Silex-WebProfiler#126 + bolt/bolt#7154 Sorry for that :) cc @fabpot Commits ------- 243e4b2 [TwigBridge] Fix BC break due required twig environment
…templates (ro0NL) This PR was squashed before being merged into the 3.4 branch (closes symfony#24236). Discussion ---------- [WebProfilerBundle] Render file links for twig templates | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | symfony#24218 | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features-->  Also tweaked default code color a bit for yaml, twig and the like. Before  After  Commits ------- 860575a [WebProfilerBundle] Render file links for twig templates
this feature has a huge impact if your page has hundreds templates, it takes ~8seconds in dev to call the load template (if you have subrequests, it's worst). I can do the PR if you're ok. |
Also tweaked default code color a bit for yaml, twig and the like.
Before

After
