MyBB Community Forums

Full Version: Can I have an example?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm writing a MyBB Plugin and would like to display a variable on the index page. However the variable $mystaffonline {$mystaffonline} does not render on my index board stats template. I'm sure I must be doing something wrong. Could someone provide me a more clear example?  Heart


<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.");
}

$plugins->add_hook('index_start', 'staffonline_index');


function staffonline_info()
{
	return array(
		"name"			=> "Staff Online",
		"description"	=> "Display currently online staff members",
		"website"		=> "https://mybb.solutions/",
		"author"		=> "JustAnotherRandomDude",
		"authorsite"	=> "https://mybb.solutions/",
		"version"		=> "1.0",
		"codename"		=> "staffonline",
		"compatibility" => "18*"
	);
}

/*
function staffonline_install()
{

}

function staffonline_is_installed()
{
	
}

function staffonline_uninstall()
{

}
*/

function staffonline_activate()
{

}

function staffonline_deactivate()
{

}

function staffonline_index()
{
	global $mybb, $db, $lang, $templates, $theme;
	$mystaffonline = "<h1>lol</h1>";
	eval($templates->render('index'));
}
content to specific template can be added using find_replace_templatesets [see this]

hello plugin file can be a good example for such requirement

(edited)
(2017-11-23, 03:22 AM)Lunorian Wrote: [ -> ]I'm writing a MyBB Plugin and would like to display a variable on the index page. However the variable $mystaffonline {$mystaffonline} does not render on my index board stats template. I'm sure I must be doing something wrong. Could someone provide me a more clear example?  Heart

You are close, you just need to globalize your custom variable:

function staffonline_index()
{
	global $mybb, $db, $lang, $templates, $theme, $mystaffonline;
	[...]
}
(2017-11-23, 11:41 AM)Wildcard Wrote: [ -> ]
(2017-11-23, 03:22 AM)Lunorian Wrote: [ -> ]I'm writing a MyBB Plugin and would like to display a variable on the index page. However the variable $mystaffonline {$mystaffonline} does not render on my index board stats template. I'm sure I must be doing something wrong. Could someone provide me a more clear example?  Heart

You are close, you just need to globalize your custom variable:

function staffonline_index()
{
	global $mybb, $db, $lang, $templates, $theme, $mystaffonline;
	[...]
}

That worked! Thanks Smile
You're welcome Cool