Is it possible to generate an absolute URL in Twig, containing username and password?:
http://foo:bar@example.com/
Is it possible to generate an absolute URL in Twig, containing username and password?:
http://foo:bar@example.com/
I suggested this as a feature for absolute_url()
but it got rejected: https://github.com/symfony/symfony/issues/30281
So here's the self-made solution I came up with: Create the following Custom Twig Filter:
public function addUsername(string $url, string $username, string $password)
{
$delimiter = '://';
$parts = explode($delimiter, $url);
return $parts[0].$delimiter.$username.':'.$password.'@'.$parts[1];
}
And use it like this:
{{ absolute_url(path('route-name'))|addUsername('foo', 'bar') }}