[solved] Template not appearing
Hello! I'm in the early stages of creating a plugin, and I think I'm missing something having to do with templates. I'm trying to get my template (characters_nav) to appear in the usercp_nav_profile template with a variable. I've confirmed that the characters_nav template exists.

This is the plugin snippet:

$plugins->add_hook('usercp_start', 'characters_nav');

function characters_nav() {

	global $mybb, $templates, $characters_nav;

	eval('$characters_nav  = "'. $templates->get('characters_nav') .'";');

Here's the variable I'm including in the usercp_nav_profile template:


Am I using the wrong hook? Missing something as far as my template goes? Totally off my rocker?

Any guidance appreciated! Smile
Unfortunately, the usercp_nav_profile template is eval()'d inside of the usercp_menu_profile() function. Which means its scope is limited to that function and the short list of variables in the global list.

Some options are available, but they may be a little hacky.

For example, you could sneak your content into a variable that is globalized in that function, $mybb. You could add your content into $mybb->user['extra_content'] (and in the template ofc) or add it to the theme variable.

Or, you could edit the template in the cache before it gets called:

function myHook()
	global $templates;

	$oldTemplate = $templates->cache['template_name'];

	// search and replace or concatenate here

	$templates->cache['template_name'] = $newContent;

Just some ideas.
Thanks for the reply! I'm glad I wasn't missing something obvious. Smile

I ended up going with the global variable like so:

$plugins->add_hook('usercp_menu', 'characters_nav');

function characters_nav() {

	global $mybb, $templates;

	eval('$mybb->user["characters_nav"]  = "'. $templates->get('characters_nav') .'";');

Template variable looks like this:


Forum Jump:

Users browsing this thread: 1 Guest(s)