MyBB Community Forums

Full Version: Plugins issues ? [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'am new to write plugins for myBB.

I'am checking the index.php and it have a $templatelist but don't seen anywhere it is used. May I get template work without it ?

Such as

<?php
/**
*  plugins page start
*/

$login_form =$templates->get('index_loginform');

?>[/php
]

Also, is there any coding convention that plugin writer must follow ?
A url link is fine.

Thanks.
$templatelist just preloads those particular templates. You can still use the other templates, but they won't be quite as fast.
The $templatelist variable is used in global.php if you're wondering.

In the code you posted, remember to include global.php, otherwise $templates is undefined.
For coding conventions, well, since you're writing a 3rd party plugin, use whatever style you're comfortable with (we can't force you to adopt a certain style Toungue).


For new pages, the general layout looks something like this:
<?php

// _Optional_ list of templates to pre-load
$templatelist = 'template_a,template_b';

// These two lines are generally required
define('IN_MYBB', 1);
require './global.php';

// here is where you do all your processing

// evaluate final result
eval('$mypage = "'.$templates->get('mypage').'";');
// output the page to the user
output_page($mypage);

?>
laie_techie, ZiNgA BuRgA Thanks,
It's more clear now Smile

OK, there is still a bit confused about how the template variable be replaced.
Do they replaced as such, say $member_online is a template variable. So, to put this
value to the template, I have to do, ( just to write the key statements )

code:
<?php
$member_online = 20;

eval('$forum_stats = "'.$templates->get('index_stats').'";');

output_page($forum_stats);

?>

template:
<div>
   <span style="color:red">Online users: {$member_online}</span>
</div>

About the code convention, I asked because someone might use code style such as
if ($a == 1) {
}

or

if ($b == 2)
{
}

so, if this is exists then, I try to following as it is might be easy reading when
sharing with someone who might required some modifications.

Thanks Smile
Yeap that's basically right.

For your preference on how you style braces for blocks, as stated, it's up to you. If you've looked through lots of code, you probably have seen both styles.
You can't really say one is better than the other.
ZiNgA BuRgA, Thanks Smile

I'am go to write something now.