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

Inserting a responseView

Marcus

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

Marcus

Well-known member
#2
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 :)
 

Chris D

XenForo developer
Staff member
#6
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.
 

Marcus

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

tyteen4a03

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

Marcus

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