MyBB Community Forums

Full Version: index_start hook not working?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Working on my next plugin to release.

While building and testing I'm finding that my function to load a template on the index is not working and I do not understand why.

PHP in plugin:
$plugins->add_hook('index_start', 'affiliates_index');
function affiliates_index() {
 global $mybb, $db, $theme, $templates;

 if ($mybb->settings['affils_active'] == 1) {
 eval("\$affiliates = \"".$templates->get("affiliates_index")."\";");
 }
}

The {$affiliates} variable is placed inside the index template. The affiliates_index template itself has "testing testing" in it just so I can see it work but it doesn't show. Am I using hooks wrong here? I'm just trying to get a template to pop up on the index.
You'd need to globalise $affiliates too if it's going to be used in a template other than one you're eval'ing inside the function, otherwise it doesn't exist outside that function.
It should only be used in the index template and not globally (assuming you mean anywhere else like footer or other.

Do you mean that I need to add it to the global line inside the function?
global $mybb, $db, $theme, $templates;
to
global $mybb, $db, $theme, $templates, $affiliates;



I should have tested before responding but adding it to the global line inside the function worked like a gem. Thank you Matt!