• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

AndyB

Well-known member
#7
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.
 

KenSmith

Active member
#8
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
 

AndyB

Well-known member
#10
The directories and files:

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

AndyB

Well-known member
#11
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);
   }
}

?>
 

AndyB

Well-known member
#12
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);
   }
}
?>