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

Purpose of ViewPublic Files


Active member
Hello All,

I'm having a bit of hard time understanding the exact purpose of files under "ViewPublic".

Let's say for example, the "XenForo_ViewPublic_Forum_List" view has "renderHtml" method that just initializes "renderedNodes" variable that's gonna be used in template. Couldn't we initialize the same in controller method itself as we initialize other variable as shown following?

$viewParams = array(
'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay(false, 0),
'onlineUsers' => $this->_getSessionActivityList(),
'boardTotals' => $this->_getBoardTotals(),
'canViewMemberList' => $this->getModelFromCache('XenForo_Model_User')->canViewMemberList(),

'threads' => $threads,

'profilePosts' => $profilePosts,
'canUpdateStatus' => XenForo_Visitor::getInstance()->canUpdateStatus()


Chris D

XenForo developer
Staff member
XenForo_ViewPublic_Forum_List is really a special case. To render the Node tree it needs to make use of the XenForo_View object and it traverses the node tree and all of its children to render the correct templates based on the definition of the node type's handler object. This wouldn't be appropriate in the Controller because conceptually the View and Controller layers should be kept separate when using MVC principles.


Active member
Thanks @Chris D, So I understand that whenever you need "XenForo_View" object to render other sub-templates as well in addition to those flat variables in controller, you should make your own View class and put the code there, right?

Chris D

XenForo developer
Staff member
Yes but not only that.

It also enables you to make adjustments to the view for other types of response such as Xml and Json.

9 times out of 10, you won't need it.