vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Displaying forumstats in a sidebar block (https://vborg.vbsupport.ru/showthread.php?t=300734)

WorldCraft 08-01-2013 10:25 PM

Displaying forumstats in a sidebar block
 
Hello. I'm trying to move the Forum Statistics from What's Going On into a forum block. I read that it was possible to put the code in a template, and then just register the template in a PHP block. I'm there, but how to I access the variables in the template?

Here's my code

Created new template called 'forumhome_forumstats'
Code:

<dl>
        <dt>{vb:rawphrase threads}</dt>
                <dd>{vb:raw totalthreads}</dd><br />
        <dt>{vb:rawphrase posts}</dt>
                <dd>{vb:raw totalposts}</dd><br />
        <dt>{vb:rawphrase members}</dt>
                <dd>{vb:raw numbermembers}</dd><br />
        <vb:if condition="$show['activemembers']">
                <dt>{vb:rawphrase active_members}</dt>
                <dd>{vb:raw activemembers}</dd>
        </vb:if>
</dl>

Created new PHP block
Code:

$templater = vB_Template::create('forumhome_forumstats');

$output = $templater->render();
return $output;

As expected it will display the HTML properly, but not the template variables. How can I access them? I'm new to using the $templater and am a bit stuck.

Thank you

kh99 08-02-2013 06:23 PM

Your php code need to include code to get and/or calculate whatever values you display. If you look at the file forum.php, you can find the code that calculates the values. I believe it depends on having 'userstats' in the $specialtemps array (near the top of the file). You would probably need to have something in your code to fetch it if it doesn't exist, so maybe something like:
Code:

global $vbulletin;

if (empty($vbulletin->userstats))
{
  $vbulletin->datastore->fetch(array('userstats'));
}

// continue with code that uses userstats to calculate statistics


WorldCraft 08-03-2013 07:29 PM

For some reason that code above breaks, and forumhome is just a white page.

Lynne 08-05-2013 01:00 AM

Then check your error_logs (if you don't know where they are, ask your host) and see what is there. But, you can't just use that code - you have to write a whole bunch of your own to go with it if you want the stats to display.

WorldCraft 08-05-2013 03:24 AM

Quote:

Originally Posted by Lynne (Post 2437183)
Then check your error_logs (if you don't know where they are, ask your host) and see what is there. But, you can't just use that code - you have to write a whole bunch of your own to go with it if you want the stats to display.

I realize I don't use just that code...it's just that everything breaks when I use what was given above. I'll see if anything of use comes up in the error log.

Edit: Just wanted to point out that $vbulletin->datastore->fetch(array('name')) breaks on two boards I work with (when using it in forum blocks).

kh99 08-05-2013 07:58 AM

Sorry about that, I hadn't tried that code at all, and there was a missing close paren which I've fixed, and it also needed a "global".

But thinking about it a little more, the forum block only appears on the home page which already loads the userstats, so you probably don't really need that code (unless you use a mod that puts the sidebar on other pages). You would need to declare $vbulletin as global (as in the first line of code I added above).

WorldCraft 08-05-2013 10:41 PM

Got it working. All I was missing was the global. I had implied that was included automatically. Sorry about that...but thank you for the help! :)


All times are GMT. The time now is 06:49 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01012 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete