twig - Silex optional locale route -
i might approaching wrong way open alternatives.
i match following sample urls using single route:
/ /welcome /en/welcome /fr/welcome /my/arbitrarily/deep/path /en/my/arbitrarily/deep/path /fr/my/arbitrarily/deep/path
etc
here have far:
$app->get('/{_locale}{path}', function (request $request) use ($app) { $path = $request->attributes->get('path'); // stuff path here }) ->value('_locale', 'en') ->assert('_locale','^(en|fr)?$') ->value('path', 'index') ->assert('path', '.*') ->bind('*');
now seems work expected, when try use twig path() or url() fails build correct url, example:#
on /foo (no locale specified on url defaults en):
{{ path('*', {path:'foo/bar'}) }}
will result correctly in
foo/bar
on /fr/foo, same call:
{{ path('*', {path:'foo/bar'}) }}
results in
frfoo/bar
this because of missing / between {_locale} , {path}, changing route to:
/{_locale}/{path}
it stops matching /foo , matches either /en/foo, /fr/foo or //foo.
i'm not sure go here :s
i didn't want use multiple routes (maybe 1 , without {_locale}) because i'm not sure how works path() function, want result of path() include current locale in url if it's not 'en' (i think i'm getting at).
can me this?
cheers
toby
declare route /{_locale}/{path}
, /{path}
.
as path() , since defined default _locale value first route , there should not issues in views.
Comments
Post a Comment