<p>My solution was to load the template directly rather than routing to the controller first.  Essentially, in my <code>registerSiteRoutes()</code> function I replaced this:</p>

<pre><code>"payment" =&gt; ['action' =&gt; 'someController/doPayment']
</code></pre>

<p>with</p>

<pre><code>"payment" =&gt; 'templateDir/core/payment'
</code></pre>

<p>I didn't even realize you could do this in <code>registerSiteRoutes()</code>!</p>

CC BY-SA 3.0
2017-01-31T19:22:28.653Z
2017-01-31T19:22:28.653Z
Billy Pilgrim
<p>everybody!</p>

<p><code>setRouteVariables()</code> doesn't appear to be working for me.  If I boil my controller function down to just this:</p>

<pre><code>public function actionSubmitForm() {
    craft()-&gt;urlManager-&gt;setRouteVariables([
        'foo' =&gt; 'bar'
    ]);
}
</code></pre>

<p>and my <code>&lt;form method="post" action="" accept-charset="UTF-8"&gt;</code> contains the following (among other inputs):</p>

<pre><code>&lt;input type="hidden" name="action" value="directoryForms/submitForm"&gt;
</code></pre>

<p>it hits the correct endpoint and then reloads the appropriate template, but it doesn't give me access to the <code>{{ foo }}</code> variable in that template.  It just tells me <code>Variable "foo" does not exist</code>.  I know it's hitting the right controller endpoint because if I <code>die()</code> there it dies as expected.</p>

<p>Any thoughts?  I've really boiled this one down as far as I can.  I must be missing something obvious.  Thanks!</p>

CC BY-SA 3.0
2017-01-31T05:14:14.107Z
Just a guess, but something else (another plugin?) is redirecting/interfering with the request of the request and not letting it continue as you're expecting?
Brad Bell
CC BY-SA 3.0
2017-01-31T13:36:27.860Z
Ah, I do have custom routes set for this plugin via registerSiteRoutes()!  How does that change how I proceed?  I'd like to pass these variables back through that custom site route.  (My full use case is filling in bad user input on validation failure)
Billy Pilgrim
CC BY-SA 3.0
2017-01-31T14:16:53.913Z
Alrighty, I've got it now.  Thanks for the push in the right directory, Brad.  I ended up routing directly to a template rather than an action which loads a template.  I didn't even realize that could be done!
Billy Pilgrim
CC BY-SA 3.0
2017-01-31T18:22:43.037Z
Would you mind adding what worked for you as an official answer in case it ends up helping someone else in the future?
Brad Bell
CC BY-SA 3.0
2017-01-31T19:19:13.530Z
Of course!  Thanks for all you do in the community, Brad.
Billy Pilgrim
<templating><routes><variable>
craft()->urlManager->setRouteVariables() loads the correct template but does not pass in the variables
# craft()->urlManager->setRouteVariables() loads the correct template but does not pass in the variables

(Asked by: username_0 on 2017-01-30)

everybody!
setRouteVariables() doesn't appear to be working for me.  If I boil my controller function down to just this:
public function actionSubmitForm() {
    craft()->urlManager->setRouteVariables([
        'foo' => 'bar'
    ]);
}

and my  contains the following (among other inputs):


it hits the correct endpoint and then reloads the appropriate template, but it doesn't give me access to the {{ foo }} variable in that template.  It just tells me Variable "foo" does not exist.  I know it's hitting the right controller endpoint because if I die() there it dies as expected.
Any thoughts?  I've really boiled this one down as far as I can.  I must be missing something obvious.  Thanks!

**Tags:** templating, routes, variable
> **Comments:**
> **username_1**: Just a guess, but something else (another plugin?) is redirecting/interfering with the request of the request and not letting it continue as you're expecting?  
> **username_0**: Ah, I do have custom routes set for this plugin via registerSiteRoutes()!  How does that change how I proceed?  I'd like to pass these variables back through that custom site route.  (My full use case is filling in bad user input on validation failure)  
> **username_0**: Alrighty, I've got it now.  Thanks for the push in the right directory, Brad.  I ended up routing directly to a template rather than an action which loads a template.  I didn't even realize that could be done!  
> **username_1**: Would you mind adding what worked for you as an official answer in case it ends up helping someone else in the future?  
> **username_0**: Of course!  Thanks for all you do in the community, Brad.  

---

## 1 answers

### Answer by username_0 on 2017-01-31. Score: 1 | Accepted answer

My solution was to load the template directly rather than routing to the controller first.  Essentially, in my registerSiteRoutes() function I replaced this:
"payment" => ['action' => 'someController/doPayment']

with
"payment" => 'templateDir/core/payment'

I didn't even realize you could do this in registerSiteRoutes()!


---

