XF 2.1 Loading a different thread_view through my controller?

cmpe

Active member
I would like to customize thread_view through my addon so that if an added bool column in xf_thread table is flagged on, the thread view looks different and loads a bunch of other custom fields.

Wondering if there is a way for me to load a completely different thread_view instead of creating template modifications to change (add conditions) to existing thread_view?

Is one way any better than the other?

thx!
 
Extending the Thread controller in your add-on is one way.

Something like this:

PHP:
public function actionIndex(ParameterBag $params)
{
    $view = parent::actionIndex($params);
    
    if ($view instance of \XF\Mvc\Reply\View)
    {
        $thread = $view->getParam('thread');
        
        if ($thread->your_bool)
        {
            $view->setTemplate('your_custom_template');
        }
    }
    
    return $view;
}
 
Back
Top Bottom