MyBB Community Forums
[solved] Template not appearing - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: [solved] Template not appearing (/thread-220221.html)



[solved] Template not appearing - Khaki - 2018-10-14

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:


{$characters_nav}


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

Any guidance appreciated! Smile


RE: Template not appearing - Wildcard - 2018-10-14

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.


RE: Template not appearing - Khaki - 2018-10-20

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:

{$mybb->user['characters_nav']}