MyBB Community Forums

Full Version: Issue With Variables in Templates Defined in Plugins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello everyone. So I am working on my second plugin, yet its pretty simple. I have a section of code that will be put right after the header and only show for certain usergroups.

I am simply using it for adsense. The issue is, is that the variable that i set as a global isn't displaying in my template...

PHP Plugin Code:

function generate_adsense()

{

	global $db, $mybb, $gac;
	$groups = explode(",",$mybb->settings["goog_adsense_disp_group"]);

	if(in_array($mybb->user["usergroup"],$groups))
	{
		$gac = $mybb->settings["goog_adsense_code"];
	}

}

Template Code:
<html>
<head>
<title>{$mybb->settings['bbname']} - Community</title>
{$headerinclude}
<script type="text/javascript">
<!--
	lang.no_new_posts = "{$lang->no_new_posts}";
	lang.click_mark_read = "{$lang->click_mark_read}";
// -->
</script>
</head>
<body id="home">
{$header}
{$gac}
{$itph}
{$topic_header}{$forums}
{$itpf}
{$boardstats}
<br style="clear: both" />
{$footer}
</body>
</html>

What am I doing wrong? Oh and I have tested, and it is retrieving the code from setting "goog_adsense_code" correctly as I printed it to the page.

Thank You.
have you included global.php ... btw, what was your first plug-in ; where is it available ?
(2011-07-08, 03:46 PM)ranjani Wrote: [ -> ]have you included global.php ... btw, what was your first plug-in ; where is it available ?

None are public. They are used privately on my forum. It was A small plugin to rewrite profile URL's. It took member.php?action=profile&uid=4 to yoursite.com/Username. And the YourSite.com/Username was a mod_rewrite to member.com?action=profile&username=Username.

And why would I need to include global. This is a standard plugin with a code hook in inc/plugins, not a new page.
Which hook are you using? global_start?

And have you tried to leave the if clause off? Does it work then?

$gac = $mybb->settings["goog_adsense_code"]; //does this work?

if(in_array($mybb->user["usergroup"],$groups))
    {
       ....
    }
(2011-07-08, 04:13 PM)Simon S. Wrote: [ -> ]Which hook are you using? global_start?

And have you tried to leave the if clause off? Does it work then?

$gac = $mybb->settings["goog_adsense_code"]; //does this work?

if(in_array($mybb->user["usergroup"],$groups))
    {
       ....
    }

no..
You are missing $templates variable in global, so your code will become like;
function generate_adsense()

{

    global $mybb, $templates, $gac;
    $groups = explode(",",$mybb->settings["goog_adsense_disp_group"]);

    if(in_array($mybb->user["usergroup"],$groups))
    {
        $gac = $mybb->settings["goog_adsense_code"];
    }

} 

P.S. No need for adding $db in global since you are not using any sql query. Also you should use global_start hook.

{$gac} remains the same in template.

It should work.
(2011-07-08, 04:44 PM)Yaldaram Wrote: [ -> ]You are missing $templates variable in global, so your code will become like;
function generate_adsense()

{

    global $mybb, $templates, $gac;
    $groups = explode(",",$mybb->settings["goog_adsense_disp_group"]);

    if(in_array($mybb->user["usergroup"],$groups))
    {
        $gac = $mybb->settings["goog_adsense_code"];
    }

} 

P.S. No need for adding $db in global since you are not using any sql query. Also you should use global_start hook.

{$gac} remains the same in template.

It should work.

I changed to global_start and global'ed $templates. No change..
What do you mean by no change ? Make sure your Group settings are correct and make sure if you are viewing the page with the same usergroup you've added in that setting.
(2011-07-08, 05:07 PM)Yaldaram Wrote: [ -> ]What do you mean by no change ? Make sure your Group settings are correct and make sure if you are viewing the page with the same usergroup you've added in that setting.

I am. I even globaled $header and tried to append to it with no luck...
You may PM me your plugin's complete code, (if you wish) so I could take a look at it. (Do not worry about the source, I respect user's privacy)
Pages: 1 2