MyBB Community Forums

Full Version: How to call templates on every page?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi

How am I able to call templates used on portal page like {$pms} and {$latestthreads} on every page?
Should I modify global.php somehow to be able to call these templates everywhere?

Thanks in advance. Smile
-Koiranpentu
Yes, you've to edit global.php inorder to use them on each page.
just use a plugin at global_start or global_end to populate that content and then use accordingly. no need for a core edit.
@Yaldaram
How I should modify my global.php? Is it something related to eval eval or something else?
I tried to do solve that somehow with eval some days ago but everything I got as result was errors.
Yes, you've to use eval()

If you're trying to add those variables on header then paste the complete code (associated to those variables) just under the $plugins->run_hooks("global_start"); hook. You've to make sure that you're pasting the complete code other wise it'll end up either not working or with errors.

For example, if you're pasting $pm variable, then it should include the following;
// Private messages box
if($mybb->settings['portal_showpms'] != 0)
{
	if($mybb->user['uid'] != 0 && $mybb->user['receivepms'] != 0 && $mybb->usergroup['canusepms'] != 0 && $mybb->settings['enablepms'] != 0)
	{
		switch($db->type)
		{
			case "sqlite":
			case "pgsql":
				$query = $db->simple_select("privatemessages", "COUNT(*) AS pms_total", "uid='".$mybb->user['uid']."'");
				$messages['pms_total'] = $db->fetch_field($query, "pms_total");
				
				$query = $db->simple_select("privatemessages", "COUNT(*) AS pms_unread", "uid='".$mybb->user['uid']."' AND CASE WHEN status = '0' AND folder = '0' THEN TRUE ELSE FALSE END");
				$messages['pms_unread'] = $db->fetch_field($query, "pms_unread");
				break;
			default:
				$query = $db->simple_select("privatemessages", "COUNT(*) AS pms_total, SUM(IF(status='0' AND folder='1','1','0')) AS pms_unread", "uid='".$mybb->user['uid']."'");
				$messages = $db->fetch_array($query);
		}
		
		// the SUM() thing returns "" instead of 0
		if($messages['pms_unread'] == "")
		{
			$messages['pms_unread'] = 0;
		}
		$lang->pms_received_new = $lang->sprintf($lang->pms_received_new, $mybb->user['username'], $messages['pms_unread']);
		eval("\$pms = \"".$templates->get("portal_pms")."\";");
	}
}
What is the right position for very own evals in global.php? I have two very own templates.

I added that pm template code below the hook. But something is wrong...
What it looks like and what is should look like:
[Image: b1DQ.jpg]
That working pm box is in portal template, and this not working is not in the portal template. I have tried to have have the {$pm} template in different pages, and locations but it looks everywhere else like that except on portal.
(the picture is edited, boxes aren't located after each other like that)
You've to load the portal language file aswell using this code;
$lang->load("portal");
Where am I supposed to put this load code?
You can add it in the next line after when declaring your function, for example after:

function plugin_name()
{
global $mybb, $lang;

$lang->load("portal");
}

likewise.
I don't really have any coding experience with PHP. I can understand some simple structures but I've never needed to code anything with PHP.

Do I need to write a function in global.php or create a new file for all this or what?

EDIT: Oops, just noticed something, will test if it helps.....
EDIT2: Yeah. Now I can see those texts in the pm. Thank you for your help for this.


Well, another question:
Where should I write my own eval lines in global.php?
Pages: 1 2