MyBB Community Forums

Full Version: best way to template/html in mybb ??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
dear all,
there are 2 ways for using a template in mybb. i am writing the points here. but which way is good and why? which method is not good and why it is not good like dis-advantage etc,

can any body tell or explain a bit?

on activation / installation we do somthing like this :

<?php
global $db, $mybb;
require MYBB_ROOT."/inc/adminfunctions_templates.php";
$template = array(
	"title"		=> "my_template1",
	"template"	=> 
		'<table>
			<tr>
				<td class="tcat">
					<strong>hello world</strong>
				</td>
			</tr>
		</table>
		',
	"sid"		=> -1
);
$db->insert_query("templates", $template);
?>

in activate how we place it :

<?php
 find_replace_templatesets(
	"index", 
	'#{\$boardstats}#', 
	"{\$my_template1}\n{\$boardstats}"
 );
?>

and how to use/bind with hook

<?php
$plugins->add_hook("pre_output_page", "hello_world");
?>

note : it will be called in check like if page is index or action is index etc.
mybb preferes : method 1

<?php
function hello_world($page)
{
	eval("\$my_template1 = \"".$templates->get("index")."\";");
}
?>

what i use, my style : method 2
if we use it directly in our method i.e, without template adding in db. just we are updating the variable

<?php
function hello_world($page)
{
	global $my_template1;
	$my_template1 = '<table>
			<tr>
				<td class="tcat">
					<strong>hello world</strong>
				</td>
			</tr>
		</table>';
}
?>
The first method is better for end-users of your plugins. They don't like to edit .php files.
they do not have to edit. the developer or owner has to edit this one. i am asking regarding development aspects and mybb conventions.

if there is any security issue in second one or something my breach security or vulnerability...
this is my concern.

concept is same , you run template from db or file, difference is tool view file system or db.

template provides same result.