Redirect to template from controller and pass data I am building a custom login process which follow these steps:


Request user email (submits to custom controller)
Check if user has an account
If they have an account, show a form requesting their password. Or if they don't have an account then send them to the registration form.


The forms exist as front end templates.

I can accomplish all these steps but when the user is redirected I need to make the email address that they entered available to the template.

My custom controller calls a service to check if the user exists which is all fine.
And I can redirect the user to the appropriate URL. But I can't figure out how to retain the email address they entered.

Currently I've just done it by appending the email as a query string but this is undesirable for a couple of reasons.

The controller currently looks like this although I feel this is totally the wrong way to be doing things.

public function actionEmailCheck() {
        $this-&gt;requirePostRequest();

        $email = Craft::$app-&gt;request-&gt;post('loginName');

        $result = MyModule::$instance-&gt;order-&gt;checkEmail($email);

        if($result) {
            $redirect = '/login/password?email='.$email;
        } else {
            $redirect = '/register?email='.$email;
        }

        $this-&gt;redirect($redirect);
    }


I feel like I should be able to set some template variables and load the appropriate template but that doesn't seem to work.

I also tried this

if($result) {
            $this-&gt;renderTemplate('/login/password', array('email'=&gt;$email));
        } else {
            $this-&gt;renderTemplate('/register', array('email'=&gt;$email));
        }


But while the template was displayed, I couldn't access the value for 'email'.

So how should I approach this?
You could do this by saving the email address to a custom session variable like this in your controller:

Craft::$app-&gt;getSession()-&gt;set('email', $email);


This should then be available in your template using:

{{ set email = craft.app.session.get('email') }}