XF 2.0 Directing different nodes to different templates

entelechy

Active member
I'm learning XF at the moment, and looking at creating custom pages. In order to be able to edit the layout of one forum node, I've added an conditional statement in the Forum controller at the end of actionForum(), changing "return $this->view('XF:Forum\View', 'forum_view', $viewParams);" to:

if ($params->node_id == 36) {
return $this->view('XF:Forum\View', 'forum_view_alternative', $viewParams);
} else {
return $this->view('XF:Forum\View', 'forum_view', $viewParams);
}

The 'forum_view' template is still being generated when I visit this node however, instead of the desired 'forum_view_alternative' template. Should I be going about it this way, or am I going to need to build a separate route and controller for the forum nodes that I want to modify?
 
Last edited:
Holy cow, who uses endif in 2018 with native PHP content o_O
Your code above works for me. Just make sure you really are using == and not ===, because route params are Strings.
 
Appreciate the heads up ;)

In the end the problem was something completely unconnected to the code, and that code worked fine.
 
Top Bottom