Skip to content

Commit 41dbf2d

Browse files
committed
feature #1563 Use app global variable for current route (seb-jean)
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
2 parents 5058252 + 66a742b commit 41dbf2d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

templates/base.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<body id="{% block body_id %}{% endblock %}">
2727

2828
{% block header %}
29-
{% set _route = app.request.get('_route') %}
29+
{% set _route = app.current_route %}
3030
<header>
3131
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
3232
<div class="container">

templates/default/_language_selector.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{% set is_active = app.request.locale == locale.code %}
2828
{% set is_rtl = locale.code in ['ar', 'fa', 'he'] %}
2929
<li class="{{ is_active ? 'active' }} {{ is_rtl ? 'rtl' }}" translate="no">
30-
<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})) }}">
30+
<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})) }}">
3131
{{ locale.name|capitalize }}
3232
<small>{{ locale.code }}</small>
3333
</a>

0 commit comments

Comments
 (0)