MyBB Community Forums

Full Version: Adding PHP Vars In Mybb Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
1. You will need to be more specific-- I think you are saying that when you edit the template that you are trying to use to eval() your variable, you are seeing no change on the page. Is that it?

2. To use language variables that incorporate parameters, use $lang->sprintf:

// in your language file
$l['my_lang_hello'] = "Hello, {1}!";

// in your plugin code
echo($lang->sprintf($lang->my_lang_hello, 'world'));
Thanks Wildcard,
My English is a little weak, I am so sorry.
1. Yes, exactly

I understood why this problem occurs. Templates loads from Default Templates from Database
I will change $theme['templateset'] value to "2"

This is contents of properties column in mybb_themes table:
a:6:{s:11:"templateset";i:2;s:11:"editortheme";s:7:"default";s:6:"imgdir";s:15:"images/foldername";s:4:"logo";s:15:"images/logo.gif";s:10:"tablespace";i:15;s:11:"borderwidth";i:0;}

Whit which sql query i can get this value?
I don't think that is your problem at all.

Why don't you post your code (or at least the relevant portions) so that I may have a better understanding of what you are attempting and how?
function myplugin()
{
	global $mybb, $lang, $db, $theme, $templates, $pluginvar, $config, $cache, $welcomeblock;

	require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	require_once MYBB_ROOT.'global.php';
	
// Prepare the main templates for use
	unset($admincplink);

// Load appropriate welcome block for the current logged in user
	if($mybb->user['uid'] != 0)
	{
		// User can access the admin cp and we're not hiding admin cp links, fetch it
		if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1)
		{
			$admin_dir = $config['admin_dir'];
			eval("\$admincplink = \"".$templates->get("header_welcomeblock_member_admin")."\";");
		}

		if($mybb->usergroup['canmodcp'] == 1)
		{
			eval("\$modcplink = \"".$templates->get("header_welcomeblock_member_moderator")."\";");
		}
	
		// Format the welcome back message
		$lang->welcome_back = $lang->sprintf($lang->welcome_back, build_profile_link($mybb->user['username'], $mybb->user['uid']), $lastvisit);

		// Tell the user their PM usage
		$lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total']));
		eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_member")."\";");
	}
// Otherwise, we have a guest
	else
	{
		switch($mybb->settings['username_method'])
		{
			case 0:
				$login_username = $lang->login_username;
				break;
			case 1:
				$login_username = $lang->login_username1;
				break;
			case 2:
				$login_username = $lang->login_username2;
				break;
			default:
				$login_username = $lang->login_username;
				break;
		}
		eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_guest")."\";");
	}

		$pluginvar .= '<div class="float_left" style="margin-left: 83px;">
		<div id="panel">'.$welcomeblock.'</div></div>'
}

When I add $theme['templateset'] = X; after requires problem solves (X is My templates sid)
(2013-07-09, 12:34 PM)amirreza13 Wrote: [ -> ]
[...]
	require_once MYBB_ROOT.'global.php';
[...]

Why are you requiring global.php? :s

Is this not a plugin script? (I am really embarrassed in advance if it is)
This is my first plugin

I thought maybe the problem is because i do not require global.php
I removed it but the problem did not solved
Which hook are you using?
I want to show plugin result in header template, so i am using global_start hook
$plugins->add_hook('global_start', 'myplugin');
EDIT: I previously replied but it was incorrect. Sorry will look again.
Thanks Wildcard

Can you found where is the problem?
Pages: 1 2 3