MyBB Community Forums

Full Version: How to echo a string in a specific MyBB template?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So lets say I'm editing the core file usercp.php and I want to echo "Hello" above the table "Your Account Summary".

How would I do that?
Find where the table "Your Account Summary" is outputted in the core file and before that just type:
echo 'Hello';
I can't, because in the core files it fetches the html as a template.
Add a new variable, lets say:
$my_var = "This is \$my_var value.";

Then use {$my_var} inside any template that gets eval'd after that line. If the template is eval'd inside a function you may need to use {$GLOBALS['my_var']} instead.
Thank you Omar G. that is exactly what I needed to know.

I always wondered how to put the {$variables} in template files, and now I know.
That is how hooks actually work. If you use a hook, lets say, "usercp_start", to achieve the same result as above you will need something like this:
$plugins->add_hook('usercp_start', 'foo');
function foo()
{
	global $my_var;

	$my_var = "This is \$my_var value."; 
}

(2015-02-12, 05:17 AM)OmarĀ G. Wrote: [ -> ]Then use {$my_var} inside any template that gets eval'd after that line hook. If the template is eval'd inside a function you may need to use {$GLOBALS['my_var']} instead.

If that hook doesn't works for you try using one that is executed before the one mentioned till you find the appropriate one. Always try to find the most appropriate hook for every piece of code you need to run.

Try it yourself.