Inserting a responseView

Marcus

Well-known member
I want to display watched Forums on top of forum_list. $response->params['watchedForums'] = $this->responseView does not work, do you have an idea for a workaround?

PHP:
class WatchedContent_ControllerPublic_Forum extends XFCP_WatchedContent_ControllerPublic_Forum
{
   public function actionIndex()
   {
     $response = parent::actionIndex();
     
     $visitor = XenForo_Visitor::getInstance();

     if($visitor['user_id'])
     {
       $nodeModel = $this->getModelFromCache('XenForo_Model_Node');
       $forumWatchModel = $this->_getForumWatchModel();
       $visitor = XenForo_Visitor::getInstance();
       
       $forumsWatched = $forumWatchModel->getUserForumWatchByUser($visitor['user_id']);
         
       
       $viewParams = array(
         'nodeList' => $nodeModel->getNodeDataForListDisplay(false, 0),
         'forumsWatched' => $forumsWatched
       );
   
       $response->params['watchedForums'] = $this->responseView('XenForo_ViewPublic_Watched_Forums', 'watch_forums', $viewParams);
     }
     
     return $response;
   }
 
PHP:
class WatchedContent_Listener
{
   public static function LoadClassController ($class, array &$extend)
   {
     switch ($class)
     {
       case 'XenForo_ControllerPublic_Forum':
       $extend[] = 'WatchedContent_ControllerPublic_Forum';
       break;
     }
   }
  
   public static function templateHook ($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
   {
     switch ($hookName)
     {
       case 'forum_list_nodes':
         $params = array_merge($template->getParams(), $hookParams);
         $contents =  $template->create('watchedcontent_forums', $params) . $contents;
         break;
     }
   }
}

Template watchedcontent_forums is just:
PHP:
{$watchedForums}

Unfortunately, it does not work :)
 
What do you mean?

I get an error that I access a View function in a non-View environment.
 
What do you mean?

I get an error that I access a View function in a non-View environment.
Can't remember if it is $response->_params or $response->params. Probably the former.

Why are you inserting a responseView into another responseView?
 
XenForo_ControllerResponse_View objects can contain a "subView"

So in your code above, you could do:

PHP:
$response->subView($this->responseView('XenForo_ViewPublic_Watched_Forums', 'watch_forums', $viewParams));

Then, use {xen:raw $_subView} in your template.
 
Thanks guys. I tried
PHP:
$response->subView($this->responseView('XenForo_ViewPublic_Watched_Forums', 'watch_forums', $viewParams));
but I get this error:
Fatal error: Call to undefined method XenForo_ControllerResponse_View::subView() in xenforo\library\WatchedContent\ControllerPublic\Forum.php on line 45
 
Uh...

PHP:
$response->subView = $this->responseView('XenForo_ViewPublic_Watched_Forums', 'watch_forums', $viewParams)

(Also, I highly suggest digging through the code since we can't remember everything off our heads :P)
 
For reference, find new posts works with subviews:

PHP:
XenForo_ControllerPublic_FindNew::getFindNewWrapper()
  { ...
     $view = $this->responseView('XenForo_ViewPublic_FindNew_Wrapper', 'find_new_wrapper', array());
     $view->subView = $subView;
    
     return $view;
   }


Template find_new_wrapper:
PHP:
{xen:raw $_subView}
 
Top Bottom