MyBB Community Forums

Full Version: Make variable from PlugIn available in template?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I'm trying to make a plugin that should provide a few extra variables for my theme. Therefore I need to know, how can I make, let's say, variable $custom_generated_html from my plugin available into the (existing) template [my template set] > Ungrouped Templates > codebuttons. So that when I do "<div>{$custom_generated_html}<div>" in that template. The content's of that variable should be inside the div element.

Basically I need to perform this every time the Editor is needed. So I tried with most of the hooks from ./newreply.php and ./newthread.php but the variable content is not outputted.

So I hook newreply_do_newreply_start, newreply_start, newthread_do_newthread_start, newthread_start to my function:
function mymod_editor_start()
{
	global $mybb, $db, $lang;
	// Grab stuff from the database then format it and then...
	eval("\$custom_generated_html = \"THIS IS JUST SOME DUMB TEXT\";");
}
And then what? The variable isn't available in the template.

I've searched over the interned for the last few hours but I've found nothing helpful. Maybe I don't know what to search for Undecided
Any variable you are using in a function you must declare as a global in order to use it in a template.
(2014-06-18, 05:10 AM)dragonexpert Wrote: [ -> ]Any variable you are using in a function you must declare as a global in order to use it in a template.

I tried to save the data in multiple global variables but the data isn't printed Undecided Can you point me to a working example? Maybe even an existing plugin that tries to achieve something similar.
(2014-06-18, 07:12 AM)effone Wrote: [ -> ]This helps?
http://community.mybb.com/thread-149714-...pid1055860

Actually that hook is only executed on the index page. My intention is to add something when the editor is invoked. And I tried that but I still can't access that variable in the [my template set] > Ungrouped Templates > codebuttons, template.

I know that the hooks I use are correct because if I do die() in function it kills the app whenever the text editor is invoked. However I wonder if the hooks are invoked after the template is already rendered. In which case my variable is useless since it already processed the template.

I still can't find a solution to this. I just need the power of PHP when the editor is invoked so that I can provide a few extra things.Things stored in the database and which are needed in that specific template Smile
If you are targeting $codebuttons; I think you have to link multiple hooks with your function as editor appears many places in MyBB. I'm still not sure though what you are aiming ...

Which hook(s) is/are you using?
(2014-06-18, 08:54 AM)effone Wrote: [ -> ]If you are targeting $codebuttons; I think you have to link multiple hooks with your function as editor appears many places in MyBB. I'm still not sure though what you are aiming ...

Which hook(s) is/are you using?

I specified some in my first post:
Quote:So I hook newreply_do_newreply_start, newreply_start, newthread_do_newthread_start, newthread_start to my function:...

Basically I'm trying to replace the default editor and I need to grab the emoticons from the database to generate the proper javascript code which is used to generate a pop-up with the emoticons.

I got the editor to work but I need the emoticon data in a specific javascript format like:
		emoticons: {
			dropdown: {
				':)': 'emoticons/smile.png',
				':angel:': 'emoticons/angel.png',
				':angry:': 'emoticons/angry.png',
				'8-)': 'emoticons/cool.png',
				":'(": 'emoticons/cwy.png',
				':ermm:': 'emoticons/ermm.png',
				':D': 'emoticons/grin.png',
				'<3': 'emoticons/heart.png',
				':(': 'emoticons/sad.png',
				':O': 'emoticons/shocked.png',
				':P': 'emoticons/tongue.png',
				';)': 'emoticons/wink.png'
			},
			more: {
				':alien:': 'emoticons/alien.png',
				':blink:': 'emoticons/blink.png',
				':blush:': 'emoticons/blush.png',
				':cheerful:': 'emoticons/cheerful.png',
				':devil:': 'emoticons/devil.png',
				':dizzy:': 'emoticons/dizzy.png',
				':getlost:': 'emoticons/getlost.png',
				':happy:': 'emoticons/happy.png',
				':kissing:': 'emoticons/kissing.png',
				':ninja:': 'emoticons/ninja.png',
				':pinch:': 'emoticons/pinch.png',
				':pouty:': 'emoticons/pouty.png',
				':sick:': 'emoticons/sick.png',
				':sideways:': 'emoticons/sideways.png',
				':silly:': 'emoticons/silly.png',
				':sleeping:': 'emoticons/sleeping.png',
				':unsure:': 'emoticons/unsure.png',
				':woot:': 'emoticons/w00t.png',
				':wassat:': 'emoticons/wassat.png'
			},
			hidden: {
				':whistling:': 'emoticons/whistling.png',
				':love:': 'emoticons/wub.png'
			}
		},

I'm trying to create a mod which removes the need for Prototype. And the first thing that I had to tackle was the editor.

So I need to get the available emoticons from the database to add them to the initialization of the editor. This is the template from [my template set] > Ungrouped Templates > codebuttons:
<script type="text/javascript" src="{$mybb->settings['bburl']}/mymod/sceditor/jquery.sceditor.bbcode.min.js?ver=1613"></script>
<link href="{$mybb->settings['bburl']}/mymod/sceditor/themes/{$theme['editortheme']}.min.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
<!--
jQuery.noConflict();
jQuery(document).ready(function($)
{
    $(function() {
        $("textarea#{$bind}").sceditor({
            plugins: "bbcode",
            style: "mymod/sceditor/jquery.sceditor.default.min.css",
            width: "100%",
            resizeWidth: false
            // ADD THE EMOTICONS HERE
       });
    });
});
// -->
</script>
If you use 'start' hooks; the $codebutton will get reset to default afterwards. Have you tried hooks like 'newthread_end' and similar?
(2014-06-18, 09:20 AM)effone Wrote: [ -> ]If you use 'start' hooks; the $codebutton will get reset to default afterwards. Have you tried hooks like 'newthread_end' and similar?

I just tried it. The same result Sad Is that template somehow generated before everything else? I'm too tired to look through the hole source right now and see what's actually going down. But I'll do it eventually if I'm unable to find a solution.
The newthread_end hook executes after assignment of default value to '$codebuttons' var but before evaluating newthread template, I'm not sure why its not working Sad

$plugins->run_hooks("newthread_end");

$forum['name'] = strip_tags($forum['name']);
$lang->newthread_in = $lang->sprintf($lang->newthread_in, $forum['name']);

eval("\$newthread = \"".$templates->get("newthread")."\";");
output_page($newthread);
Pages: 1 2 3