Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[TwigBridge] Expose current route inAppVariable#47535

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.2fromHeahDude:feat/twig-current-route
Sep 13, 2022

Conversation

@HeahDude
Copy link
Contributor

@HeahDudeHeahDude commentedSep 10, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
Tickets~
LicenseMIT
Doc PRTODO

In my experience, a Symfony web project using Twig always comes with templates usingapp.request.attributes.get('_route'), a most common exemple:

<ul>    <liclass="{{'some_route'==app.request.attributes.get('_route')?'active' }}">...</li>    ...</ul>

(An idea of how much it can be used at:https://github.com/search?q=app.request.attributes.get%28%27_route%27%29&type=code).

The current way is somehow complex and not easy to discover, also trying to search thecurrent keyword in Routing and Twig sections of the docs does not show the expected exemple.
However searching for_route may lead tohttps://symfony.com/doc/current/routing.html#getting-the-route-name-and-parameters.

I propose with this PR to introduce two small helpers in the globalAppVariable:

{%setcurrent_route=app.current_route %}{%setcurrent_params=app.current_route_parameters %}

ChrisRiddell, OskarStark, alexislefebvre, freerich, florentdestremau, and tacman reacted with thumbs up emoji
@HeahDudeHeahDudeforce-pushed thefeat/twig-current-route branch 2 times, most recently from2e9a971 to43dd724CompareSeptember 10, 2022 09:18
@fabpot
Copy link
Member

Thank you@HeahDude.

fabpot added a commit that referenced this pull requestDec 2, 2022
…teParameters methods (Kocal)This PR was merged into the 6.2 branch.Discussion----------[TwigBridge] Fix casing of getCurrentRoute/getCurrentRouteParameters methods| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | yes| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->| License       | MIT| Doc PR        | -Following of#47535, those two methods were named like this in order to get `app.current_route` and `app.current_route_parameters`, however PHPStorm autocomplete for `app.current_Route` and `app.current_Route_Parameters`.I'm not sure if this is a PHPStorm-only issue or not.**Before:**![image](https://user-images.githubusercontent.com/2103975/205177835-fe5c64d7-2581-44be-8f3f-39f7cd4dcf9e.png)**After:**<img width="604" alt="image" src="https://user-images.githubusercontent.com/2103975/205177787-b3e55d95-4a0f-40ea-8b65-a0b3ddc447f0.png">Commits-------67588b3 [TwigBridge] Fix casing of currentRoute/currentRouteParameters methods
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@stofstofstof approved these changes

@xabbuhxabbuhxabbuh approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

7 participants

@HeahDude@fabpot@nicolas-grekas@stof@xabbuh@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp