MyBB Community Forums

Full Version: Templates not working as they should
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

So I am going to lay this out as best I can so everyone can understand. I have been trying to get my SteamID plugin working with a template that will add another element to the member profile page right after reputation (see screenshot below)

[Image: BldI7c7.png]


So what I would like to have happen is, get an element to show up right after the reputation row, and right before the warning level row.

My plugin is still small (the templates were going to be placeholders for now until I get it fleshed out)
Here is my code:

Here is my activate function, where I create the template itself, do all my setting configs and where I also add the {$steamID_profile} template var into the member_profile template (I will also show this in a bit):


function steamID_activate() {
global $db, $templates;

$steamID_group = array(
        'gid'    => 'NULL',
        'name'  => 'SteamID',
        'title'      => 'SteamID Plugin',
        'description'    => 'Settings for the SteamID Plugin',
        'disporder'    => "1",
        'isdefault'  => "0",
    );
	
	$db->insert_query('settinggroups', $steamID_group);
 $gid = $db->insert_id(); 
 
 
 $steamID_setting = array(
        'sid'            => 'NULL',
        'name'        => 'steamID_enable',
        'title'            => 'Enable the SteamID Plugin',
        'description'    => 'If you set this option to yes, your users will have their SteamIDs linked to their profile after linking',
        'optionscode'    => 'yesno',
        'value'        => '1',
        'disporder'        => 1,
        'gid'            => intval($gid),
    ); 
	
	$db->insert_query('settings', $steamID_setting); 
	
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	
	//create template
	$steamID_template = array(
		'steamID'	=> "<tr>
	<td class=\"trow1\"><strong>SteamID login</strong></td>
	<td class=\"trow1\">SteamLoginDataHere</td>
</tr>
<tr>
	<td class=\"trow2\"><strong>Steam Linked since</strong></td>
	<td class=\"trow2\">DateSinceFirstSteamLink</td>
</tr>"
	);
	
	//insert template(s) into database
	foreach($steamID_template as $template_title => $template_data)
	{
		$insert_templates = array(
			'title' => $db->escape_string($template_title),
			'template' => $db->escape_string($template_data),
			'sid' => "-1",
			'version' => $info['intver'],
			'dateline' => TIME_NOW
			);
		$db->insert_query('templates', $insert_templates);
	}
	
	if(!find_replace_templatesets("member_profile", '#{\$reputation}(\r?)\n#', "{\$steamID_profile}\n{\$reputation}\n"))
	{
		find_replace_templatesets("member_profile", '#{\$reputation}(\r?)\n#', "{\$steamID_profile}\n{\$reputation}\n");
	} 
	
	
  rebuild_settings();
   
  
} 
 
Here is a screenshot of my member_profile template after activation:

[Image: AN3YKCm.png]

As you can see the {$steamID_profile} template var is present.

Here is my deactivate function just for sake of having it:

function steamID_deactivate()
  {
  global $db;
 $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('steamID_enable')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='steamID'");
	
	$db->delete_query("templates", "title='steamID'");
	
	
	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	
	find_replace_templatesets("member_profile", '#{\$steamID_profile}(\r?)\n#', "", 0);
rebuild_settings();

 }

Which as you can tell removes the template (steamID) from the templates DB, and then reverts the member_profile back to the original.

So now that I have that in there, as far as I know what is left is for me to eval() out the statement in a function that I have hooked to a specific hook and the information template data will show (I have been following another plugin that I downloaded to make sure that I have done this correctly. I could be missing something here, please do share).

Here is my hook code:

$plugins->add_hook("member_profile_end","steamID_memprofile");

Here is the function that hooks to:

function steamID_memprofile()
{
	global $db, $mybb, $lang, $templates;
	
		eval("\$steamID_profile = \"".$templates->get("steamID")."\";");
		
}


All I want this function to do is put out the template "steamID" into my {$steamID_profile} variable. According to all the other examples I have seen this works.

Now when I upload this into my plugins directory, I am able to activate/deactivate and it adds/removes the template from the DB and changes the member_profile template, along with creates/destroys the steamID template (in global templates).

HOWEVER, on the member profile page, there is nothing that shows up, I decided perhaps it is hidden and I know from my research that the templates->get() function will comment when a template is being grabbed. like so <--!Start: template_name end: template_name-->

Here is a screenshot of the "view source" option in chrome:

[Image: F6rBkLa.png]
At around line 210 - 212 my code should be coming up as shown but it is not.

I would include another screenshot of my member profile page, but it doesnt look any different from before.

Any help would be appreciated! Thanks!

Please note, this plugin is VERY early development, and this site is a complete test site for a live implementation of the plugin on a site with over 10k daily hits.

As you might imagine this is pretty important that I get this small roadblock removed from my path!

Hope you guys/girls can help!

Best,
Poseidon

--SOLVED--

I had missed the fact that you need to have your template placeholder variable global in the function you are hooking:

function steamID_memprofile()
{
	global $db, $mybb, $lang, $templates, $steamID_profile;
	
		//eval("\$steamID_profile = \"".$templates->get("steamID")."\";");
		$steamID_profile = eval($templates->render('steamID'));
		
}

Notice now $steamID_profile is linked as a global variable and it works flawlessly. 

Stupid error on my part, thanks to anyone who was thinking about, or getting ready to post.

Thanks!
~ Poseidon