Skip to content

Commit

Permalink
feature #1563 Use app global variable for current route (seb-jean)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the main branch.

Discussion
----------

Use app global variable for current route

URL: https://symfony.com/blog/new-in-symfony-6-2-dx-improvements#simpler-way-to-get-current-route-in-templates

Commits
-------

66a742b Use app global variable for current route
  • Loading branch information
javiereguiluz committed Feb 24, 2025
2 parents 5058252 + 66a742b commit 41dbf2d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<body id="{% block body_id %}{% endblock %}">

{% block header %}
{% set _route = app.request.get('_route') %}
{% set _route = app.current_route %}
<header>
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion templates/default/_language_selector.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% set is_active = app.request.locale == locale.code %}
{% set is_rtl = locale.code in ['ar', 'fa', 'he'] %}
<li class="{{ is_active ? 'active' }} {{ is_rtl ? 'rtl' }}" translate="no">
<a class="stretched-link" lang="{{ locale.code }}" hreflang="{{ locale.code }}" href="{{ path(app.request.get('_route', 'blog_index'), app.request.get('_route_params', [])|merge({_locale: locale.code})) }}">
<a class="stretched-link" lang="{{ locale.code }}" hreflang="{{ locale.code }}" href="{{ path(app.current_route ?? 'blog_index', app.current_route_parameters|merge({_locale: locale.code})) }}">
{{ locale.name|capitalize }}
<small>{{ locale.code }}</small>
</a>
Expand Down

0 comments on commit 41dbf2d

Please # to comment.