redirect to url and set variable in template In a plugin, I am trying to redirect to a url, and set some values on the template. It's not working. Here is a simplified (not working) test case:

Template lives at templates/test.twig:

someVar is defined? {{ someVar is defined ? 'yes' : 'no' }}

&lt;form method="post" action="" accept-charset="UTF-8"&gt;
  {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="site/test"&gt;
  &lt;input type="hidden" name="redirect" value="/test"&gt;
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;


Controller code (which does get called):

public function actionTest() {
    craft()-&gt;urlManager-&gt;setRouteVariables(array(
        'someVar' =&gt; 23
    ));
    $this-&gt;redirectToPostedUrl();
}


What I expect, is that when I first visit the page, someVar isn't defined, but when I submit the form and revist the page, someVar will be defined (and equal 23). But it is not defined.
If you want to reload the form, you don't need to (indeed, shouldn't) redirect to the posted URL. That's why the form's action attribute is empty.

This should work:

public function actionTest() {
    craft()-&gt;urlManager-&gt;setRouteVariables(array(
        'someVar' =&gt; 23
    ));
}