Your Location is: Home > Symfony

How to use url_encode with returnTo in twig

From: South View: 2491 Karthik 


I have a condition in which an user has to be verified by a link received in mail. I have some url_encode ed data in the url which I am appending with the url

The actual url is link this

I want the returnTo part to be url_encode ed so that the user is made logged in first. I tried using this in the email-template twig

{% set siteUrl = '' %}
{% set returnToPath = '/register/verify-my-email'|url_encode %}

{% set verifyMyEmailUrl = siteUrl ~ "/register/api/login?returnTo=" ~ returnToPath ~ "?" ~ {
    'key': script.TOKEN_KEY,
    'value': script.TOKEN_VALUE,
    'lang': script.PREFERRED_LANG,
}|url_encode %}

The url when accessed goes to login first but after login the url becomes link this

The register/api/login is not replaced properly by register/verify-my-email and also the later url_encode ed paramters are not appended properly

I want the url to be like below after login

Can some one help me on this as I am quiet new to twig and email-template design?

Best answer