<p>This is indeed possible.  You'll want to update your route to point to an array with and identify your controller path with the key <code>action</code>:</p>

<pre><code>public function registerCpRoutes()
{
  return array(
    'pluginname/edit' =&gt; array('action' =&gt; 'pluginName/editItem'),
  );
}
</code></pre>

<p>In your plugin controller, you can create any number of variables you need and hand them off to your template as the second argument in the renderTemplate() method:</p>

<pre><code>// PluginNameController.php
public function actionEditItem()
{
    // Create any variables you want available in your template
    $variables['variable'] = craft()-&gt;request-&gt;getSegment(3);       

    $variables['items'] = craft()-&gt;pluginName-&gt;getAllItems();

    // Load a particular template and with all of the variables you've created
    $this-&gt;renderTemplate('pluginname/_edit', $variables);
}
</code></pre>

<p>Check out the article <a href="http://straightupcraft.com/articles/how-do-i-setup-a-route-to-point-to-a-controller-action-instead-of-a-template" rel="nofollow">How do I setup a route to point to a controller action instead of a template?</a> on Straight Up Craft for a more in depth discussion that also goes into how to render the template from your control, hand off variables to your template, and reference multiple controllers.</p>

CC BY-SA 3.0
2014-09-30T13:39:24.310Z
Ben, this is just what I was looking for. How would I pass in a variable using CpRoutes(). ie. 'pluginname/edit/variable' => array('action' => 'pluginName/editItem'),
David A McInnis
CC BY-SA 3.0
2014-09-30T15:31:50.427Z
@DavidAaronMcInnis I've updated the answer to give an example of how to create variables for your template in the controller.
Ben Parizek
CC BY-SA 3.0
2014-09-30T05:43:58.190Z
2014-09-30T15:30:40.937Z
2014-09-30T15:30:40.937Z
Ben Parizek
<p>I love routes, but they appear limited to loading a specific template. What about loading a plugin/controller based on the route instead? Anyway to do this in craft or am I limited to .htaccess?</p>

<routes><htaccess>
Using Routes to load Controller
# Using Routes to load Controller

(Asked by: username_0 on 2014-09-30)

I love routes, but they appear limited to loading a specific template. What about loading a plugin/controller based on the route instead? Anyway to do this in craft or am I limited to .htaccess?

**Tags:** routes, htaccess


---

## 1 answers

### Answer by username_1 on 2014-09-30. Score: 3 | Accepted answer

This is indeed possible.  You'll want to update your route to point to an array with and identify your controller path with the key action:
public function registerCpRoutes()
{
  return array(
    'pluginname/edit' => array('action' => 'pluginName/editItem'),
  );
}

In your plugin controller, you can create any number of variables you need and hand them off to your template as the second argument in the renderTemplate() method:
// PluginNameController.php
public function actionEditItem()
{
    // Create any variables you want available in your template
    $variables['variable'] = craft()->request->getSegment(3);       

    $variables['items'] = craft()->pluginName->getAllItems();

    // Load a particular template and with all of the variables you've created
    $this->renderTemplate('pluginname/_edit', $variables);
}

Check out the article How do I setup a route to point to a controller action instead of a template? on Straight Up Craft for a more in depth discussion that also goes into how to render the template from your control, hand off variables to your template, and reference multiple controllers.

> **Comments:**
> **username_0**: Ben, this is just what I was looking for. How would I pass in a variable using CpRoutes(). ie. 'pluginname/edit/variable' => array('action' => 'pluginName/editItem'),  
> **username_1**: @DavidAaronMcInnis I've updated the answer to give an example of how to create variables for your template in the controller.  

---

