Skip to content

Documenting debug:twig command #10232

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 6, 2018

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Aug 28, 2018

@javiereguiluz javiereguiluz added the Waiting Code Merge Docs for features pending to be merged label Sep 5, 2018
symfony-splitter pushed a commit to symfony/twig-bridge 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
-------

7ef3d39a4c [TwigBridge] Added template \"name\" argument to debug:twig command to find their paths
fabpot added a commit to symfony/symfony 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
Copy link
Member Author

yceruto commented Sep 5, 2018

Related PR was merged 🎉 now we can take care of this one :) Cheers!

@javiereguiluz javiereguiluz removed the Waiting Code Merge Docs for features pending to be merged label Sep 5, 2018
@@ -71,6 +71,13 @@ in the ``vendor/acme/foo-bar/templates/`` directory, you can refer to it as:

{{ include('@foo_bar/sidebar.twig') }}

Execute this command to verify if your template name is correct and know which
template file will be loaded:
Copy link
Member

Choose a reason for hiding this comment

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

Just asking: what happens if the app doesn't use physical files to store templates? (they are stored in the database for example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sadly, at this moment, the command only work for physical files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw, I'm not sure if the TwigBridge & TwigBundle support such feature.

# filter output by any keyword
$ php bin/console debug:twig --filter=date

Also, you can verify any template name to know which template file will be loaded:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can merge this last comment into the main code block?

.. code-block:: terminal

    ...

    # pass a template path to show the physical file which will be loaded
    $ php bin/console debug:twig @Twig/Exception/error.html.twig

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

@javiereguiluz javiereguiluz added this to the 4.2 milestone Sep 6, 2018
@javiereguiluz javiereguiluz merged commit 1026020 into symfony:master Sep 6, 2018
javiereguiluz added a commit 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
@javiereguiluz
Copy link
Member

This was finally merged. Yonel, thanks as always for creating these great little utilities to improve developer experience!

@yceruto yceruto deleted the debug_twig_command branch September 6, 2018 13:24
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.

3 participants