How do I create an add-on with a route that calls a template

I would like to know how to edit the Index.php file so the andy_showdeleted template is displayed under the breadcrumb. Currently I get echoed "test" above the header and the following under the breadcrumb:

Route showdeleted/ could not be found.
 
I'm debating whether to respond because I'm still learning the nuances of this myself.
But hopefully I can provide some direction for you.

Returning a template from a controller looks like this:
Code:
class Andy_ControllerPublic_ShowDeleted extends XenForo_ControllerPublic_Abstract
{
   public function actionIndex()
   {
     $viewParams = array( );  //  this would include any variables that you want to send to your template
     return $this->responseView('Andy_ViewPublic_ShowDeleted', 'your_template_name', $viewParams);
   }
That code would be in Andy/ControllerPublic/ShowDeleted.php

However, your Route Prefix needs another piece to connect it all together.

Something like this in Andy/Route/Prefix/ShowDeleted.php

Code:
<?php

class Andy_Route_Prefix_ShowDeleted implements XenForo_Route_Interface
{
  /**
  * Match a specific route for an already matched prefix.
  *
  * @see XenForo_Route_Interface::match()
  */
  public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
  {
  return $router->getRouteMatch('Andy_ControllerPublic_ShowDeleted', $routePath);
  }
}
And the Route Prefix setting in the ACP should point to Andy_Route_Prefix_ShowDeleted instead of your current value of Andy_ShowDeleted_Index
 
The directories and files:

library
--Andy
----ShowDeleted
------ControllerPublic
--------ShowDeleted.php
------Route
--------Prefix
----------ShowDeleted.php
 
library/Andy/ShowDeleted/ControllerPublic/ShowDeleted.php

PHP:
<?php

class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XenForo_ControllerPublic_Abstract
{
   public function actionIndex()
   {
     $viewParams = array( );  //  this would include any variables that you want to send to your template
     return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted', 'andy_showdeleted', $viewParams);
   }
}

?>
 
library/Andy/ShowDeleted/Route/Prefix/ShowDeleted.php

PHP:
<?php

class Andy_ShowDeleted_Route_Prefix_ShowDeleted implements XenForo_Route_Interface
{
   /**
   * Match a specific route for an already matched prefix.
   *
   * @see XenForo_Route_Interface::match()
   */
   public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
   {
     return $router->getRouteMatch('Andy_ShowDeleted_ControllerPublic_ShowDeleted', $routePath);
   }
}
?>
 
@AndyB
Drats. Tripped over this thread and was hoping to see your work on templates. What templates did you end up creating?
 
Back
Top Bottom