2011-10-30, 12:51 PM
I'm going to migrate a PHP application earlier written by me to a MyBB plugin. It also happens to be my first MyBB plugin. I came across the wiki pages, but as I can see that those do not detail upon authoring templates. Googling further, I came across a plugin, which makes use of the following template
The plugin consists of few more pages which are written in PHP. The approach of the author is to keep on appending the dynamically generated HTML to a $content PHP variable & then executing the following code
Since little amount of HTML is generated by the PHP, that approach worked well in that plugin. But, my application is larger & therefore generates bulk amount of HTML throughout the PHP pages. Adapting the same approach will turn my code messy. What I want to know is whether it is the ONLY approach to deal with templates or is there any better way to do that?
<html>
<head>
<title>{\$mybb->settings[\'bbname\']} - {\$title}</title>
<script type=\"text/javascript\">
function validate_form(){
var title=document.forms[\"snippet\"][\"txtTitle\"].value;
if (title==null || title==\"\"){
alert(\"Title must be filled out\");
return false;
}
if (title.length > 50){
alert(\"Title must not be longer than 50 characters\");
return false;
}
var category=document.forms[\"snippet\"][\"ddLang\"].selectedIndex;
if (category==0){
alert(\"You must select a category\");
return false;
}
var snip=document.forms[\"snippet\"][\"txtSnippet\"].value;
if (snip==null || snip==\"\")
{
alert(\"You must enter a snippet\");
return false;
}
return true;
}
</script>
{\$headerinclude}
</head>
<body>
{\$header}
<table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\">
<tr>
<td class=\"thead\"><strong>{\$title}</strong></td>
</tr>
{\$content}
</table>
{\$footer}
</body>
</html>
The plugin consists of few more pages which are written in PHP. The approach of the author is to keep on appending the dynamically generated HTML to a $content PHP variable & then executing the following code
$template=$templates->get("my_plugin_teamplate");
eval("\$page=\"".$template."\";");
output_page($page);
Since little amount of HTML is generated by the PHP, that approach worked well in that plugin. But, my application is larger & therefore generates bulk amount of HTML throughout the PHP pages. Adapting the same approach will turn my code messy. What I want to know is whether it is the ONLY approach to deal with templates or is there any better way to do that?