MyBB Community Forums

Full Version: Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey!
I'm a new plugin developer and I understand most of the stuff but some thing are really confusing to me. One of them is templates. What exactly are templates? Like I know you can create them but that's all. Also how do variables in templates work? Do they get passed in automatically? Also if I wanted for example to add a button to every thread in showthread.php how would I got about it? Also how to get for example the thread id? Is there a public resource where I can see how to get all the parameters of a page or all the globals and their parameters?? Also what is a breadcrumb? And I'm reading this page https://docs.mybb.com/1.8/development/pl...-new-page/ and idk why did they put this in: 
eval('$sections  = "' . $templates->get('hello_world_template') . '";');


thanks in advance
below guidance could be helpful
* MyBB Plugins Explained
* Plugin MyBB Base & Plugin MySql

templates system is used to display required content easily. see templates related guidance

for adding a button to thread page we have to modify showthread related template(s)

breadcrumb is used for easy navigation of the web site / forum
eg. MyBB Community Forums Resources Plugins Plugin Development

see MyBB variables - php cross reference

eval('$sections  = "' . $templates->get('hello_world_template') . '";'); 
in simple words, variable sections value is evaluated through hello_world_template
(2017-11-01, 12:45 PM).m. Wrote: [ -> ]below guidance could be helpful
* MyBB Plugins Explained
* Plugin MyBB Base & Plugin MySql

templates system is used to display required content easily. see templates related guidance

for adding a button to thread page we have to modify showthread related template(s)

breadcrumb is used for easy navigation of the web site / forum
eg. MyBB Community Forums Resources Plugins Plugin Development

see MyBB variables - php cross reference

eval('$sections  = "' . $templates->get('hello_world_template') . '";'); 
in simple words, variable sections value is evaluated through hello_world_template
I get all the stuff you said just I don't understand the eval. Why not just say
$sections = templates->get('hellworl_template');
Why does it need to be evaluated?
I don't understand that? Why even use eval if you can just regularly set the variable?
Also which template should I modify to add buttons to every post?
And how to get the post id of the post im adding buttons to?
eval('$sections  = "' . $templates->get('hello_world_template') . '";'); 
I get all the stuff, I just don't understand the eval. Why not just say 
$sections = templates->get('hellworl_template');
Why does it need to be evaluated?
I don't understand that? Why even use eval if you can just regularly set the variable?
Also which template should I modify to add buttons to every post?
And how to get the post id of the post im adding buttons to?
eval() is used as templates are strings that contain PHP variables. eval evaluates the string contents of a template and replaces any PHP variables within it (yes, this is nasty and is a relic of the past - the template is something we are hoping to change pretty soon).

To add buttons to every post, you should add code to the postbit and postbit_classic templates. The two templates represent different styles of post display (user details horizontally and user details vertically, respectively).

Your plugin should use the find_replace_templatesets() function during its _activate() function to add a new variable to the two above templates. You would then hook into the postbit function to fill the variable that you added with your new button.

In order to get the post ID (pid) of the post, you can use the $post variable that is passed to functions hooked into the post bit hook. You can get the pid from that array ($post['pid']).