MyBB Community Forums

Full Version: Php and templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm interested in developing plugins/modifications for mybb and have basic php/mysql knowledge but im a bit lost as to how the php files and the template files come together and so how I pass the data calculated in the php files to existing or new templates.

I've looked around for exisiting guides but only found information about the plugin activation/deactivation file and hooks.

Thanks,
Alec
It'd be easier if you specified a little more information, but I'll try to give an example.

Say we have a template named my_custom_template:
The value of <em>my sum</em> is <strong>{$mysum}</strong>!
And the PHP code:
$mysum = 5 + 2;

eval('$mytemplate = "'.$templates->get('my_custom_template').'";');

After executing the above code, the variable $mytemplate will have the following data:
The value of <em>my sum</em> is <strong>7</strong>!

Hope that helps.
Ah so you just pass through a variable and the eval grabs the template file to display it. What about where there is a template inside a template for instance there is 'portal_stats' inside the 'portal' template?

Thanks,
Alec
Eval the first one into a variable, then eval the second template.

eg
eval('$stats = "'.$templates->get('portal_stats').'";');
eval('$portal = "'.$templates->get('portal').'";');
The {$stats} variable should be in the portal template.