Getting data for templates?

Renari

Member
So I tried to make something simple, from what I've read I thought this would work. However it doesn't seem to be getting the data it needs from it's parent template and I'm unsure how to get the information myself to pass to the template. Some things I could probably read from the database however I can't help but feel that would be adding unnecessary queries, since it is already read somewhere else.

PHP:
<?php
class BottomMembersOnline_Listener
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        if ($hookName == 'page_container_breadcrumb_bottom')
        {
            $params = $template->getParams();
            $output = $template->create('BottomMembersOnline_online', $params);
            $output .= $contents;
            $contents = $output;
        }
    }
}

HTML:
<div style="clear: both;" class="section membersOnline userList"> 
    <div class="secondaryContent">
        <h3><a href="{xen:link online}" title="{xen:phrase see_all_online_users}">{xen:phrase members_online_now}</a></h3>
 
        <xen:if is="{$onlineUsers.records}">
 
            <xen:if is="{$visitor.user_id}">
                <xen:if hascontent="true">
                <h4 class="minorHeading"><a href="{xen:link account/following}">{xen:phrase people_you_follow}:</a></h4>
                <ul class="followedOnline">
                    <xen:contentcheck>
                        <xen:foreach loop="$onlineUsers.records" value="$user">
                            <xen:if is="{$user.followed}">
                                <li title="{$user.username}" class="Tooltip"><xen:avatar user="$user" size="s" img="true" class="_plainImage" /></li>
                            </xen:if>
                        </xen:foreach>
                    </xen:contentcheck>
                </ul>
                <h4 class="minorHeading"><a href="{xen:link members}">{xen:phrase members}:</a></h4>
                </xen:if>
            </xen:if>
     
            <ol class="listInline">
                <xen:foreach loop="$onlineUsers.records" value="$user" i="$i">
                    <xen:if is="{$i} <= {$onlineUsers.limit}">
                        <li>
                        <xen:if is="{$user.user_id}">
                            <a href="{xen:link members, $user}"
                                class="username{xen:if '!{$user.visible}', ' invisible'}{xen:if {$user.followed}, ' followed'}">{$user.username}</a><xen:if is="{$i} < {$onlineUsers.limit}">,</xen:if>
                        <xen:else />
                            {xen:phrase guest}<xen:if is="{$i} < {$onlineUsers.limit}">,</xen:if>
                        </xen:if>
                        </li>
                    </xen:if>
                </xen:foreach>
                <xen:if is="{$onlineUsers.recordsUnseen}">
                    <li class="moreLink">... <a href="{xen:link online}" title="{xen:phrase see_all_visitors}">{xen:phrase and_x_more, 'count={xen:number $onlineUsers.recordsUnseen}'}</a></li>
                </xen:if>
            </ol>
        </xen:if>
 
        <div class="footnote">
            {xen:phrase online_now_x_members_y_guests_z, 'total={xen:number $onlineUsers.total}', 'members={xen:number $onlineUsers.members}', 'guests={xen:number $onlineUsers.guests}'}
        </div>
    </div>
</div>

The above will always output a member list that says 0 people are online.
 

Attachments

  • BottomMembersOnline.webp
    BottomMembersOnline.webp
    4.7 KB · Views: 7
Those parameters are available for forum_list template, not page_container.

Add listener for templateCreate event, when forum_list template is parsed, parse your template and save output. Then in your hook prepend that output to $contents.
 
Back
Top Bottom