MyBB Community Forums

Full Version: Best coding practice for importing templates during plugin installation?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've just started redeveloping the Inferno Shoutbox for MyBB 1.8. One thing that was a bit of a problem for me when making the original plugin was determining the most practical method for loading the plugin's HTML template code. It seems most plugins just have the HTML hard-coded in the PHP files which I think takes up way too much space and just looks wrong. with the old version I decided just to get the HTML using file_get_contents(); which looks much cleaner in the code and completely separates the template from the PHP file. I'm wondering if there is a "proper" alternative or if what I did is okay.
Why not use MyBB's template engine? Some developers use pluginlibrary to make it easier to manage the templates for plugins, but I've always found it pretty simple to add the templates without it when global templates are not an issue.
I ever prefer to make templates on install funtions ant then wit a function hooked to a page i use eval method and goes fine xD
(2014-09-16, 10:08 PM)Darth Apple Wrote: [ -> ]Why not use MyBB's template engine? Some developers use pluginlibrary to make it easier to manage the templates for plugins, but I've always found it pretty simple to add the templates without it when global templates are not an issue.

I use MyBB's templating engine to render my plugin's templates. My question is focused on the one-time operation of installing the template into the database. Most people have their templates hard-coded as variables in their PHP files which looks terrible. See here for an example of what I mean. I want to have the template separated from the PHP file for easy editing while I am developing the plugin. Maybe I'm not wording this properly
Well, you can freely separate them to another file if that makes it more comfortable for you. Nothing is wrong with that, from user's point of view it doesn't matter at all.
(2014-09-16, 10:14 PM)ectomatt Wrote: [ -> ]
(2014-09-16, 10:08 PM)Darth Apple Wrote: [ -> ]Why not use MyBB's template engine? Some developers use pluginlibrary to make it easier to manage the templates for plugins, but I've always found it pretty simple to add the templates without it when global templates are not an issue.

I use MyBB's templating engine to render my plugin's templates. My question is focused on the one-time operation of installing the template into the database. Most people have their templates hard-coded as variables in their PHP files which looks terrible. See here for an example of what I mean. I want to have the template separated from the PHP file for easy editing while I am developing the plugin. Maybe I'm not wording this properly

Ah, well that makes more sense. Toungue

I'm personally just lazy and put them straight into the plugin file. I suppose that's not really the proper way to do it, but I'm lazy and it works. Toungue
Since the main purpose of that is to store the template in the database, I wouldn't say it's wrong. You're actually not mixing up templating with logic which might bother the readability of your code.

And as long as it works, it's fine Big Grin
What I do is I store the templates as HTML files under a templates directory. I then use a DirectoryIterator to iterate all the templates and add them to an array before using PluginLibrary to actually add them.