Skip to content

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

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

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Jul 17, 2018

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
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 debug-twig-loader-typo-alt
Other outputs

Discovering more alternatives:
debug-twig-loader-not-found-many-alt

Unknown template name:
debug-twig-loader-not-found

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.

@nicolas-grekas
Copy link
Member

Should it be a dedicated command or an option on the debug:twig one?
I'm not sure growing the list of commands with this one is justified (it's a "minor" command, isn't it?)

@yceruto
Copy link
Member Author

yceruto commented Jul 23, 2018

IMHO the name argument doesn't seem like an option, but an argument that represents a pure action (find the path of the template name).

At first I thought about adding it to debug:twig but this already has a main argument (filter) for the general info of Twig (functions, filters, tests, globals), I thought that adding this new feature would be a mess or it would require a complete refactor of the command (including passing the argument filter to option --filter and making name as the main argument of the command).

I'd also like to have everything in one command, but its initial design should change then. I imagine something like this:

$ b/c debug:twig # show general info

# proposal 1 (without refactor)
$ b/c debug:twig escape # filter the general info
$ b/c debug:twig --find=@Twig/Exception/error.html.twig # find the template path

# proposal 2 (with refactor) much better to me.
$ b/c debug:twig @Twig/Exception/error.html.twig # find the template path
$ b/c debug:twig --filter=escape # filter the general info

Do you prefer this?

@yceruto yceruto force-pushed the debug_twig_loader_command branch 2 times, most recently from cbb48c5 to 628e66c Compare August 1, 2018 23:45
@yceruto yceruto changed the title [TwigBridge] Added new command to debug a template name [TwigBridge] Added template "name" argument to debug:twig command to find their paths Aug 1, 2018
@yceruto yceruto force-pushed the debug_twig_loader_command branch from 628e66c to 2216514 Compare August 2, 2018 01:51
@yceruto
Copy link
Member Author

yceruto commented Aug 2, 2018

@nicolas-grekas I added a second commit with your suggestion and # proposal 2. I also added a missing (minor) feature.

MINOR FEATURE:

  • allowed --filter with --format=json

@yceruto yceruto force-pushed the debug_twig_loader_command branch 2 times, most recently from 26b9e60 to 642313c Compare August 2, 2018 11:14
@yceruto
Copy link
Member Author

yceruto commented Aug 2, 2018

Fixing AppVeyor failure...

Status: Needs Work

@yceruto yceruto force-pushed the debug_twig_loader_command branch 4 times, most recently from 2fb0110 to 7c26264 Compare August 2, 2018 12:20
@yceruto
Copy link
Member Author

yceruto commented Aug 2, 2018

(Travis failures unrelated)

Status: Needs Review

@yceruto
Copy link
Member Author

yceruto commented Aug 28, 2018

Status: Needs Review

@fabpot fabpot force-pushed the debug_twig_loader_command branch from c3a9eb1 to 7ef3d39 Compare September 5, 2018 08:33
@fabpot
Copy link
Member

fabpot commented Sep 5, 2018

Thank you @yceruto.

@fabpot fabpot merged commit 7ef3d39 into symfony:master Sep 5, 2018
fabpot added a commit that referenced this pull request 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
@yceruto yceruto deleted the debug_twig_loader_command branch September 5, 2018 12:36
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Sep 6, 2018
This PR was merged into the master branch.

Discussion
----------

Documenting debug:twig command

See symfony/symfony#27981

Commits
-------

1026020 Documenting debug:twig command
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants