Your Location is: Home > Symfony

How to use url_encode with returnTo in twig

From: South View: 2491 Karthik 

Question

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

mysite.net/register/api/login?returnTo=/register/verify-my-email?key=AC26HBASJDHBJHABSDJH683746F7BE3C3B816DB8ABD1FE1B8&value=NXJWL3H8LDSHBFJSDHBFJSHD876816YP9P9KJ71O2BQFKZUAIKTFMV2L3S&lang=en-US

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 = 'mysite.net' %}
{% 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

mysite.net/register/api/%252Fregistration%252Fverify-my-email%253Fkey=AC26HBASJDHBJHABSDJH683746F7BE3C3B816DB8ABD1FE1B8

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

mysite.net/register/verify-my-email?key=AC26HBASJDHBJHABSDJH683746F7BE3C3B816DB8ABD1FE1B8&value=NXJWL3H8LDSHBFJSDHBFJSHD876816YP9P9KJ71O2BQFKZUAIKTFMV2L3S&lang=en-US

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

Best answer