Twig连接和功能

I've written a special function for TWIG that manages the languages URL's.

$URLWithLang = new Twig_SimpleFilter('url', function($URL)
{
    if(substr($URL, -1) == '/'){
        $URL = "/".$_GET['lang']."/".$URL;
    }
    else{
        $URL = "/".$_GET['lang']."/".$URL."/";      
    }
    return $URL;
});

The functions works perfect with URL's like: {{'about-us'|url}} => en/about-us/

However, when using a variable and text, like below. It put the language for some reason in between.

{{'/bl'~ car.carURL|url}} => /bl/en/252-fiat-panda/

How should i change the statement in order to make it output. /en/bl/252-fiat-panda?

Thanks in advance!

This is expected due to operator precedence. Try the following:

{{ ('/bl'~ car.carURL)|url }}`