Custom pages not displaying forum data

kiwhen

Member
I've been at this for a while, but I'm getting nowhere fast. I thought this would be one of the most frequently asked questions regarding XenForo development as well, but I can't find anyone who has attempted this, been successful and at the same time provided the solution for me to see. This is as close as I get, but this guy doesn't provide any answers, just the same question. Pretty much.

Anyhow, I got this custom page, and I would like to display the usual sidebar on it. Using the <xen:sidebar>-code, I do get the top block from the normal forum layout, which includes my own statistics. This is cool and all, but I would like to have the online user list, status updates and stuff too.

When I try to just include the template elements for these, they show up correctly, but the information is wrong. It says that no one is online, the forum contains no posts, and there are no status updates.

Research points in various directions, mostly towards that XenForo, for some reason, blocks requests from "outsiders". So I ask; Why in God's name would anyone design it this way? Really?

I suppose I need to put in a callback or something like that to actually grab the data and not just the design for the elements, but again - I'm getting nowhere. Someone also pointed at the "XenForo_ControllerPublic_Forum" class and the actionIndex() function, but I'm not quite sure how to use that to get the desired result.

Of course, I would like to understand the solution, not just install some kind of add-on that does everything for me. That would leave me none the wiser.
 
Research points in various directions, mostly towards that XenForo, for some reason, blocks requests from "outsiders".
This is not the case.

XenForo has a very open and accessible API that allows developers to do pretty much anything they like to the existing code and create new code in addition to the existing code.

You've hit the nail on the head in terms of needing to do something to get data passed to that template.

The reason why you have probably been pointed into the direction of XenForo_ControllerPublic_Forum: actionIndex() is because if you look in there you will see already how, for example, the online users list data is passed to the template:

PHP:
        $viewParams = array(
            'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay(false, 0),
            'onlineUsers' => $this->_getSessionActivityList(),
            'boardTotals' => $this->_getBoardTotals()
        );

        return $this->responseView('XenForo_ViewPublic_Forum_List', 'forum_list', $viewParams);

The forum index is one of the simplest examples there is, actually.

The $viewParams array contains the data that is then passed to the view which renders the forum_list template. So you need to have something like this in your custom code.
 
Thanks for the reply!

To follow up, is there a way to access the $viewParams-data without creating my own PHP-file for this? I mean, all the info I need is already in there, so it would be a bit overkill to make a custom class for fetching data that I already have. Or at least should have.

The most obvious thing to do in my mind, was to reference this file in the callback tab, but that just gave me an error that said something about static access. If it really is a static function, I should be able to use it without importing it, right?

forum_list does not appear to set any of the variables it uses, and I can't quite figure out where they are coming from ($boardTotals and $onlineUsers).
 
The forum_list itself my not directly use $boardTotals and $onlineUsers as they are in the sidebar which are included in that template. e.g:

Code:
<xen:sidebar>
    <xen:edithint template="sidebar.css" />
   
    <xen:hook name="forum_list_sidebar">
        <xen:include template="sidebar_online_users" />

So the $onlineUsers variable is passed to the forum_list template, and any other templates included in the forum_list template, e.g. sidebar_online_users will also be able to use those variables.

The error about static classes is because the callback needs to be static, and the controllers are non-static.

Using callbacks probably is the most simple route, but you still have to write your own PHP to do it.

You mention in the thread title "custom pages"... how have you created custom pages so far? Have you extended an existing controller? Have you created your own page node?
 
So if I go like this:
Code:
<xen:sidebar>
  <xen:edithint template="sidebar.css" /> <!-- <- Probably not required, but still -->
  <xen:hook name="forum_list_sidebar">
  <xen:include template="sidebar_online_users" />
</xen:hook>
</xen:sidebar>
I should get some results? 'Cause I don't. :(

For this particular page, I don't have a custom callback. I have used that before to get dynamic content, but for this one, I don't really need it for anything else than getting this sidebar working. I also have to do a remote configuration for this, on another board (1.2). Same kind of page really, just plain text with the "default" sidebar (user panel, online block, statistics). This is why it would be great if I could do everything without having to get into the FTP for the remote server. Plus, it would be a whole lot easier to explain to the remote server's administrator, if everything was stored in a single page node. Oh, and my board is running 1.1. I believe I read about some changes made to the hook-system between the two versions. Not quite sure what, though, since I'm not that into using xen-tags in the first place. Obviously. :whistle:
 
Top Bottom