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

Inserting a responseView

Discussion in 'XenForo Development Discussions' started by Marcus, Jul 29, 2013.

  1. Marcus

    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(false0),
             
    'forumsWatched' => $forumsWatched
           
    );
       
           
    $response->params['watchedForums'] = $this->responseView('XenForo_ViewPublic_Watched_Forums''watch_forums'$viewParams);
         }
         
         return 
    $response;
       }
     
  2. Marcus

    Marcus Well-Known Member

    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 $hookParamsXenForo_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 :)
     
  3. tyteen4a03

    tyteen4a03 Well-Known Member

    Pretty sure it's _params.
     
  4. Marcus

    Marcus Well-Known Member

    What do you mean?

    I get an error that I access a View function in a non-View environment.
     
  5. tyteen4a03

    tyteen4a03 Well-Known Member

    Can't remember if it is $response->_params or $response->params. Probably the former.

    Why are you inserting a responseView into another responseView?
     
    Marcus likes this.
  6. Chris D

    Chris D XenForo Developer Staff Member

    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 and tyteen4a03 like this.
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    $response->subView
     
    Marcus and Chris D like this.
  8. Marcus

    Marcus Well-Known Member

    Thanks guys. I tried
    PHP:
    $response->subView($this->responseView('XenForo_ViewPublic_Watched_Forums''watch_forums'$viewParams));
    but I get this error:
     
  9. tyteen4a03

    tyteen4a03 Well-Known Member

    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)
     
    Chris D and Marcus like this.
  10. Chris D

    Chris D XenForo Developer Staff Member

    Yeah I got it wrong. Probably should have looked at my Media controller which was about 3 clicks away, but meh :p
     
    Jeremy and Marcus like this.
  11. Marcus

    Marcus Well-Known Member

  12. Marcus

    Marcus Well-Known Member

    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}
     

Share This Page